Seite 1 von 1

TikZ - "underfull hbox" bei Verwendung von fit

Verfasst: Do 10. Mai 2012, 04:24
von Omega
Hallo,

es ist schon spät und ich verzweifle langsam beim Kompilieren des folgenden Codes:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}
\begin{tikzpicture}[box/.style={draw}]
		\node[box]     (a)	at (0,0)	{Inhalt A};
		\node[box]     (b)	at (4,2)	{Inhalt B};
		\node[draw, very thick, fit=(a)(b)] {}; %9 Zeile im editor
\end{tikzpicture}
\end{document}

Ich erhalte die Fehlermeldung "Underfull \hbox (badness 6141) in paragraph at lines 9--9".

Was ist die Ursache dessen und wie beseitige ich die Fehlermeldung?

Ich weiß nicht, ob es an der Uhrzeit liegt :wink: oder ob hier ein tikz internes Problem vorliegt.

Ich möchte lediglich einen sich anpassenden Rahmen um bestehende Nodes zeichnen lassen.

Verfasst: Do 10. Mai 2012, 11:39
von cgnieder
Die Ursache ist ein bisschen versteckt.

Bei der \node, die mit fit gezeichnet wurde, werden die Optionen text width und align gesetzt.

Aus dem pgfmanual v2.10 S. 357:
The exact effects of the fit option are the following:
  1. A minimal bounding box containing all coordinates is computed. Note that if a coordinate like (a) is used that contain a node name, this has the same effect as explicitly providing the (a.north) and (a.south) and (a.west) and (a.east). If you wish to refer only to the center of the a node, use (a.center) instead.
  2. The text width option is set to the width of this bounding box.
  3. The align=center option is set.
  4. The anchor is set to center.
  5. The at position of the node is set to the center of the computed bounding box.
  6. After the node has been typeset, its height and depth are adjusted such that they add up to the height of the computed bounding box and such that the text of the node is vertically centered inside the box.
Das führt in diesem Fall dazu, dass die Box Deines Beispiels einen minimalen Text erwartet:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}

\begin{tikzpicture}[box/.style={draw}]
  \node[box] (a) at (0,0) {Inhalt A}; 
  \node[box] (b) at (4,2) {Inhalt B};
  \node[draw, very thick, fit=(a) (b)] {blabla blabla blabla};
\end{tikzpicture}

\end{document}
Wenn Du nicht vorhast, einen Text in die \node zu schreiben, könntest Du das align Verhalten manuell setzen:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}

\begin{tikzpicture}[box/.style={draw}]
  \node[box] (a) at (0,0) {Inhalt A}; 
  \node[box] (b) at (4,2) {Inhalt B};
  \node[draw, very thick, fit=(a) (b),align=none] {};
\end{tikzpicture}

\end{document}
Gruß

Verfasst: Do 10. Mai 2012, 16:26
von Omega
Hey Clemens,

vielen Dank für deine rasche und vollkommen zutreffende Lösung! :D

Ich muss gestehen, ich wäre auf diese Maßnahme nicht gekommen.

Jetzt kann ich wieder beruhigt "halbschlafen" :wink:


Schöne Grüße