4
\documentclass[tikz]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \path node[inner sep=0,draw,text width=40mm]
      { \parbox{\hsize}
          { \parshape 4 0mm 40mm 5mm 35mm 10mm 30mm 15mm 25mm
            \fboxrule0.1pt
            \fboxsep0pt
            \fbox{hello world}\newline
            \fbox{hello world}\newline
            \fbox{hello world}
            \vspace{-\lineskip} % WHY AFTER THE PICTURE THAT FOLLOWS, NOT BEFORE?
            \begin{tikzpicture}
              \path node[draw,text width=24mm]
                { \parbox{\hsize}
                    { \begin{gather*}
                        2+2=4
                      \end{gather*}
                    }
                };
            \end{tikzpicture}
          }
      };
  \end{tikzpicture}
\end{document}
Bernard
  • 271,350
bp2017
  • 3,756
  • 1
  • 13
  • 33
  • 1
    You can use \saveboxes to properly nest tikzpictures, see https://tex.stackexchange.com/q/47377/121799. –  Jun 10 '19 at 18:31
  • why have you got those parboxes there at all?, you can remove both of them. – David Carlisle Jun 10 '19 at 19:23
  • @bp2017 did you try? – David Carlisle Jun 10 '19 at 19:42
  • you can use \parshape if you are in vertical mode, as you are in a tikz node if you specify the text width key. standalone class does not change that. – David Carlisle Jun 10 '19 at 19:44
  • 1
    @bp2017 you are using gather here which is a vertical mode display environment, but you do not need \parbox basically if you use text width on a node it is a parbox already (actually it is a minipage but that is almost the same thing, mostly using the same code.) – David Carlisle Jun 10 '19 at 20:24
  • the parbox are not just saving you worrying if you need it, as in an earlier question of yours you are nesting vertically centred boxes so throwing away all information about the top and bottom baselines of the text in the node, making positioning much harder. – David Carlisle Jun 10 '19 at 20:26
  • @DavidCarlisle, I'm trying to grasp what you're saying. Do you mean \parbox inside a node throws away information about top and bottom baselines of text in the node? – bp2017 Jun 10 '19 at 23:31
  • @DavidCarlisle, I've tried using text width without \parbox for vertical-mode math just now. Vertical spacing of the equation becomes uneven on the bottom compared to when \parbox is used. With \parbox the equation's top and bottom spacing is even (without \parbox it's not). I guess that's one of the reasons I use \parbox. (I have to think of other reasons, nothing comes to mind yet.) But it's interesting that \parbox makes information about vertical spacing to be lost inside the node. – bp2017 Jun 10 '19 at 23:34
  • 1
    @bp2017 yes if course, a parbox only has a single reference point, by default in its vertical centre, so there is only one baseline as far as the node can see. If you put a paragraph directly in the node then it can be aligned on the top or bottom baseline or the vertical center, that was why you had to use \strut in an earlier question – David Carlisle Jun 10 '19 at 23:36
  • @DavidCarlisle, specifying text width doesn't make \parshape work inside the node. (I am posting the code in the next comment.) – bp2017 Jun 12 '19 at 05:24
  • @DavidCarlisle, \documentclass[tikz]{standalone}

    \usepackage{tikz}

    \begin{document} \begin{tikzpicture} \path node [ draw=blue, inner sep=0pt, line width=1.5pt, text width=40mm ] { \parshape 4 0mm 40mm 5mm 35mm 10mm 30mm 15mm 25mm \fboxrule0.1pt \fboxsep0pt \fbox{hello world}\newline \fbox{hello world}\newline \fbox{hello world} }; \end{tikzpicture} \end{document}

    – bp2017 Jun 12 '19 at 05:24
  • 1
    @bp2017 hard to tell with comment formatting but you are probably missing a blank line at the end of the paragraph before the } I get indented boxes when I added linebreaks to your code from the comment, not really tikz, you would get the same from any group. – David Carlisle Jun 12 '19 at 06:59

2 Answers2

6

It is unrelated to tikz, if you use \vspace in horizontal mode it is inserted after linebreaking.

aaa\vspace{1cm}bbb

adds the space after bbb

You possibly wanted to have blank line before the \vspace so that the space is added in vertical mode at the point it appears in the source.

David Carlisle
  • 757,742
5

The third line is split because it doesn't fit. But every \vspace material in a paragraph will be inserted after the line in which the command happens to fall (it uses \vadjust).

Just add \newline. And don't overcomplicate things.

\documentclass[border=2]{standalone}
\usepackage{amsmath}

\setlength{\fboxrule}{0.1pt}
\setlength{\fboxsep}{0pt}

\begin{document}

\fbox{%
  \parbox{40mm}{
    \parshape 4 0mm 40mm 5mm 35mm 10mm 30mm 15mm 25mm
      \fbox{hello world}\newline
      \fbox{hello world}\newline
      \fbox{hello world}
      \vspace{-\lineskip}\newline
      \fbox{%
        \parbox{24mm}{
          \begin{gather*}
            2+2=4
          \end{gather*}
        }%
      }
   }
}

\end{document}

enter image description here

egreg
  • 1,121,712