Here's a little example: two "outer" nodes, each one containing a graph (formed with "inner" nodes) and some edges and arrows connecting outer nodes to outer nodes, and inner nodes from one graph to inner nodes of the other; the remember picture
option lets you access inner and outer nodes at any time:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}[remember picture,
inner/.style={circle,draw=blue!50,fill=blue!20,thick,inner sep=3pt},
outer/.style={draw=green,fill=green!20,thick,inner sep=10pt}
]
\node[outer,draw=green] (A) {
\begin{tikzpicture}
\node [inner,draw=blue] (ai) {A1};
\node [inner,draw=blue,below=of ai] (aii) {A2};
\node [inner,draw=blue,right=of aii] (aiii) {A3};
\draw[red,thick] (ai) -- (aii) -- (aiii) -- (ai);
\end{tikzpicture}
};
\node[outer,draw=green,right=of A] (B) {
\begin{tikzpicture}
\node [inner,draw=blue] (bi) {B1};
\node [inner,draw=blue,below=of bi] (bii) {B2};
\node [inner,draw=blue,right=of bii] (biii) {B3};
\node [inner,draw=blue,right=of bi] (biv) {B4};
\draw[red,thick] (bi) -- (bii) -- (biii) -- (biv) -- (bi) -- (biii);
\end{tikzpicture}
};
\draw[thick,orange,->] (ai) -- (bii);
\draw[orange,->] (aiii) -- (bi);
\draw[orange,->] (A.90) -- ($(A.90)+(0,1)$) -| (B);
\end{tikzpicture}
\end{document}
Typically one would include a \strut
at the beginning. Note also that you have some spurious spaces in your macro definition (you need some strategic placements of %
). See What is the use of percent signs (%
) at the end of lines? I'm also guessing your use of .96\textwidth
results from some overfull \hbox
es. You can adjust this width to fit perfectly within the text block as well...
Here's perhaps something that you're after:
\newcommand{\field}[1]{%
\noindent%
\framebox[\linewidth][l]{%
\parbox[t]{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{%
\raggedright\strut#1%
}%
}%
}
Here is its use in a MWE:
\documentclass{article}
\newcommand{\field}[1]{%
\noindent%
\framebox[\linewidth][l]{%
\parbox[t]{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{%
\raggedright\strut#1%
}%
}%
}
\begin{document}
\field{Some test}
\field{}
\field{I'm trying to draw a vertical box around one or more lines of
text (for a field in a pre-filled form), but some of the fields may
be empty and in these cases, the box should be the same vertical
height as when there is only one line (or even just one character)
of content within the box.}
\end{document}
Depending on your usage, you may also consider ending with a \strut
, allowing for adequate space if the last line has no descender.
Best Answer
The
shapes.multipart
library ofTikZ
can be helpful (refer to Section 48.6 Shapes with Multiple Text Parts of the pgfmanual); a little example: