0

How can I make a repeatable node (node is probably not the right word here) that looks like this:

complex node

The Field values are individual input texts.

I've thought about using \newcommand to make the outer node and then fill the inside of the outer node with other nodes and text, but I run out of arguments; \newcommand takes up to 9 inputs and this would require 10 inputs plus the positioning and labeling of the outer node.

There is the TeX hack that "allows" more than 9 inputs: How to define a command that takes more than 9 arguments

Is there a better way to do this?

First attempt

This is starting to look like something.

first attempt

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\newcommand\iitem[3]{%say \node [#1,minimum size=3cm] (#2) {}; \node [anchor=north west] (title) at (#2.north west) {\footnotesize Title}; \node [anchor=north west] (title field) at (title.south east) {\footnotesize #3}; }

\begin{document} \begin{tikzpicture}

\iitem{draw}{test}{demo title}; %\node[left=of test,draw] (test 2) {test 2 node};

\end{tikzpicture} \end{document}

2 Answers2

2

You can use \newcommand with just a single argument, but that argument consists of all 10 fields separated by /s (forward slashes). Then \foreach (which doesn't actually loop since there's only one argument) can be used to read each of the fields into a different variable.

If any of your "fields" contains a forward slash it must be enclosed in braces, e.g., {Field/1}/{Field/2}/...

Then the rest of the macro draws the image with lines and rectangles, placing the text as node contents. You can change the values of \fieldheight and \fieldwidth to adjust the size of the image.

enter image description here

\documentclass{article}

\usepackage{tikz}

\newcommand{\fieldheight}{.5cm} \newcommand{\fieldwidth}{1.5cm} \newcommand{\makecard}[1]{\tikz[font=\sffamily, text height=1.5ex, text depth=0ex]{ \foreach \ffa/\ffb/\ffc/\ffd/\ffe/\fff/\ffg/\ffh/\ffi/\ffj in {#1}{ \draw[thick] (0,0) node[below right]{Title} rectangle (4\fieldwidth,-9\fieldheight); \draw (0,-2\fieldheight)rectangle node[above]{\ffa}(4\fieldwidth,-2\fieldheight); \draw (0,-3\fieldheight)node[above right]{Dwg No.}-- node[above, pos=.65]{\ffb}(4\fieldwidth,-3\fieldheight); \draw (0,-4\fieldheight)node[above right]{SCH No.}-- node[above, pos=.65]{\ffc}(4\fieldwidth,-4\fieldheight); \draw (0,-5\fieldheight)node[above right]{Ref Des}-- node[above, pos=.75]{Qty}(4\fieldwidth,-5\fieldheight); \draw (0,-6\fieldheight)node[above right]{\ffd}-- node[above, pos=.75]{\ffe}(4\fieldwidth,-6\fieldheight); \draw (0,-8\fieldheight)node[above right]{\fff} rectangle (\fieldwidth,-7\fieldheight); \draw (\fieldwidth,-8\fieldheight)node[above right]{\ffg} rectangle (2\fieldwidth,-7\fieldheight); \draw (2\fieldwidth,-8\fieldheight)node[above right]{\ffh} rectangle (3\fieldwidth,-7\fieldheight); \draw (3\fieldwidth,-8\fieldheight)node[above right]{\ffi} rectangle (4\fieldwidth,-7\fieldheight); \path (0,-9\fieldheight)rectangle node[above]{\ffj}(4\fieldwidth,-9*\fieldheight); }}}

\begin{document}

\makecard{Field 1/Field 2/Field 3/Field 4/Field 5/Field 6/Field 7/Field 8/Field 9/Field 10}

\end{document}

Sandy G
  • 42,558
1

TikZ is not required here. Your "node" is a simple tabular.

\documentclass[border=1mm]{standalone}
\usepackage{pgffor}

\newcommand\fieldWidth{1.3cm} \newcommand\makecard[1]{% \foreach \ffa/\ffb/\ffc/\ffd/\ffe/\fff/\ffg/\ffh/\ffi/\ffj in {#1} {% \sffamily% \begin{tabular}{|p{\fieldWidth}p{\fieldWidth}p{\fieldWidth}p{\fieldWidth}|} \hline \multicolumn{4}{|l|}{Title}\ & \multicolumn{2}{c}{\ffa} & \ \hline Dwg No. && \multicolumn{1}{c}{\ffb} & \ \hline SCH No. && \multicolumn{1}{c}{\ffc} & \ \hline Ref Des && \multicolumn{2}{c|}{Qty}\ \hline \ffd && \multicolumn{2}{c|}{\ffe}\ \hline &&&\ \hline \multicolumn{1}{|l|}{\fff} & \multicolumn{1}{l|}{\ffg} & \multicolumn{1}{l|}{\ffh} & \multicolumn{1}{l|}{\ffi}\ \hline \multicolumn{4}{|c|}{\ffj}\ \hline \end{tabular}% }% }

\begin{document} \makecard{Field 1/Field 2/Field 3/Field 4/Field 5/Field 6/Field 7/Field 8/Field 9/Field 10} \end{document}

output

Unknown
  • 822