6

The text inside the nodes is not streched to the right side of the node by using \hfill. Could it be the reason that it doesn't work with font=\tiny? But I need the text that small and I would like that the explanation text is at the right side inside the node and the short term like Frg 1 is on the left side inside the node.


\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,arrows,backgrounds,fit,matrix}

\begin{document}

\begin{figure} [H]

\begin{tikzpicture}
[font=\tiny,
 pfeil/.style                   ={draw,->,shorten <=0pt,>=stealth', thick, -latex',shorten >=0pt},
 stext/.style                   ={draw,solid, fill=gray!10, text width=25em,minimum height=1em, drop shadow, rounded corners},
 snr/.style                     ={drop shadow,fill=gray!10,draw,solid,circle,minimum width=4mm,inner sep=0pt},
 every matrix/.style    ={matrix of nodes, row sep=1mm, column sep=3mm,fill=gray!40,draw=black,dashed,rounded corners,inner sep=2mm}]

    \newcommand{\beschr}[1]{\hfill\textit{#1}};

    \matrix (einlegen)      
        {
            \node   (e11)       {}; &   \node   (e12)       [snr]   {1.};   &   \node   (e13)       [stext] {Frg 1\beschr{Freigabe Einfahrt Bauteil}};                  \\
            \node   (e21)       {}; &   \node   (e22)       [snr]   {2.};   &   \node   (e23)       [stext] {MZ 11 V\beschr{Sauger ein}};      \\                                                               
            \node   (e31)       {}; &   \node   (e32)       [snr]   {3.};   &   \node   (e33)       [stext] {Frg 2\beschr{Freigabe Ausfahrt Bauteil}};                  \\
        };

    \node   [fit=(e11)(e31),label={[rotate=90,xshift=1mm]center:\textbf\tiny{Einlegen}}] {};

    \matrix (arbeitsstellung)   [below=.3cm of einlegen]
        {
            \node   (a11)       {}; &   \node   (a12)       [snr]   {4.};   & \node (a13)       [stext] {MZ 12 V\beschr{Spanner Innenblech vorw\"arts}};            \\
            \node   (a21)       {}; &   \node   (a22)       [snr]   {5.};   & \node (a23)       [stext] {M1 \& M2 V\beschr{B\"ugel M1 \& M2 vorw\"arts}};           \\
            \node   (a31)       {}; &   \node   (a32)       [snr]   {6.};   & \node (a33)       [stext] {M3 \& M6 V\beschr{B\"ugel M3 \& M6 vorw\"arts}};           \\
            \node   (a41)       {}; &   \node   (a42)       [snr]   {7.};   & \node (a43)       [stext] {M4 \& M5 V\beschr{B\"ugel M4 \& M5 vorw\"arts}};           \\
            \node   (a51)       {}; &   \node   (a52)       [snr]   {8.};   & \node (a53)       [stext] {MZ 13 V\beschr{Klemmeinheit l\"osen}}; \\                  
            \node   (a61)       {}; &   \node   (a62)       [snr]   {9.};   & \node (a63)       [stext] {MZ 14 V\beschr{Niederhalteraufnahme vorw\"arts}};          \\
            \node   (a71)       {}; &   \node   (a72)       [snr]   {10.};& \node   (a73)       [stext] {MZ 15-19 V\beschr{Niederhalteraufnahmen vorw\"arts}};          \\
            \node   (a81)       {}; &   \node   (a82)       [snr]   {11.};& \node   (a83)       [stext] {MZ 21-22 V\beschr{Niederhalterzustellungen vorw\"arts}};           \\
            \node   (a91)       {}; &   \node   (a92)       [snr]   {12.};& \node   (a93)       [stext] {MZ 23-24 V\beschr{Niederhalterzustellungen vorw\"arts}};           \\
            \node   (a101)  {}; &   \node   (a102)  [snr]   {13.};& \node   (a103)  [stext] {MZ 20 V\beschr{Sperrventil vorw\"arts}};   \\
        };



\node   [fit=(a11)(a101),label={[rotate=90]center:\textbf\tiny{Falze in Arbeitsstellung}}] {};
\begin{scope}   [every path/.style=pfeil]
                \path   (e33)   --  (a13);
            \end{scope}

    \end{tikzpicture}

\end{figure}
  • 1
    If you use a matrix of nodes, you just need to include node text in every position. Instead of \node (a22) [snr] {5.}; just 5.. With this syntax, every node is named matrix name-row-column. If you need to change any option can use |[options list]| node text... – Ignasi Jun 28 '13 at 8:20
  • 1
    ... You can also add column 1/.style={nodes={anchor=base}}, column 2/.style={nodes={snr}},column 3/.style={nodes={stext}}},nodes in empty cells to every matrix style. With this syntax, einlegen matrix could be written with \matrix (einlegen) { & 1. & {Frg 1\beschr{Freigabe Einfahrt Bauteil}}\ & 2. & {MZ 11 V\beschr{Sauger ein}}\\ & 3. &{Frg 2\beschr{Freigabe Ausfahrt Bauteil}}\\}; – Ignasi Jun 28 '13 at 8:26
  • 1
    ... Vertical nodes don't need to be labels, regular nodes are OK. You don't need fit to place them because you can use any matrix internal node to place it, something like \node [rotate=90,] at ([ xshift=1mm]einlegen-2-1) {\textbf\tiny{Einlegen}}; could be enough. – Ignasi Jun 28 '13 at 8:32
6

What happens here?

The problem here is, that the value of text width (which is stored in the internal macro \tikz@text@width) is evaluated twice for the construction of the node. First when the content of the font key (stored in \tikz@textfont) is active, and then again after the node text is collected but without \tikz@textfont executed:

  1. Before the node text is collected in \tikz@do@fig:

    \tikz@textfont%
    \ifx\tikz@text@width\pgfutil@empty%
    \else%
      \begingroup%
        \pgfmathsetlength{\pgf@x}{\tikz@text@width}%
        \pgfutil@minipage[t]{\pgf@x}\leavevmode\hbox{}%
        \tikz@text@action%
    \fi%
    

    The \tikz@textfont which contains \tiny does obviously change font-dependent sizes like em and ex which result in a minipage width of 25em = 170.14122pt.

  2. After the node text is collected and the box is created (still only 170pt wide) there is another check in \tikz@fig@continue:

    \ifx\tikz@text@width\pgfutil@empty%
    \else%
      \pgfmathsetlength{\pgf@x}{\tikz@text@width}%
      \wd\pgfnodeparttextbox=\pgf@x%
    \fi%
    

    You see, the same happens again but now without \tiny active which results in a \pgf@x set to around 25em = 250pt. The width of the constructed box is then set to these 250pt.

  3. You have a node with a box 250pt wide but only contents of 170pt width.

(I consider this at least a non-feature. Why is text width checked again anyway?)

Fixes

We can fix this in various ways.

Don’t use font-dependent dimensions …

… in text width, text height and text depth (the latter two won’t get executed twice like the width but you will still get results that are not in relation with the actual font-size inside the node).

With text width=5cm I get:

enter image description here

Don’t use the font key for font-size switches.

You could just issue \tiny right at the start of your tikzpicture (but then all font-related dimensions get changed, which seems in your example only be in the minimum height key of the stext style). With text width=25em and \tiny active in the TikZ picture, I get:

enter image description here

Or use it manually in the node text itself, this is most of the times not an option because it would involve more manual work which we wanted to avoid with the font key in the first place.

Only evaluate the text width input once.

If you insist on using font-dependent sizes you could let text width evaluate its content right when it is used (which means that these dimension will always be evaluated with the font-size active outside of the node). The fix consist of:

\makeatletter
\tikzset{text width/.code=\pgfmathparse{#1}\edef\tikz@text@width{+\pgfmathresult pt}}
\makeatother

With this fix and text width=15em, I get:

enter image description here

Don’t let TikZ “correct” the width of the box.

With no warranty that this doesn’t break anything, we can simply remove the second check for \tikz@text@width from the construction code. etoolbox makes this very simply:

\usepackage{etoolbox}
\makeatletter
%\patchcmd\tikz@fig@continue{\wd\pgfnodeparttextbox=\pgf@x}{}{}
\patchcmd\tikz@fig@continue{%
    \ifx\tikz@text@width\pgfutil@empty%
    \else%
      \pgfmathsetlength{\pgf@x}{\tikz@text@width}%
      \wd\pgfnodeparttextbox=\pgf@x%
    \fi%
}{}{}
\makeatother

(Same output as above.)

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.