0

I have prepared a series of illustrated tables for a technical brochure, and I have finally elected to use the option "matrix of nodes" of Tikz. I could not manage however to center (on the same vertical center line) the large labels such as "40" or "40C1" with the graphics above. How to do this? Strangely, the bottom labels, such a s "40 contacts #20" are perfectly aligned.

\documentclass{article}
\usepackage[draft]{graphicx} 
\usepackage{tikz}
\begin{document}
\centering
\begin{tikzpicture} [font=\sf,
mynode/.style={rectangle, text width = 4.5 cm, anchor=north, inner sep=0pt},
myheader/.style={rectangle, fill, color=blue!20, text width = 4.55cm, text=black, text centered, font={\Huge, \sf}, inner sep=5pt},
mylabel/.style={rectangle, fill, minimum height=10ex, color=black!10, text=black, text width = 4.55 cm, anchor=north, inner sep=5pt},
]
\matrix [column sep=0pt , row sep=0mm, align=center, draw, rectangle]
{
\node {\includegraphics[width=0.3\textwidth]{40Insert.pdf}}; &
\node {\includegraphics[width=0.3\textwidth]{40C1Inser.pdf}};
&\node {\includegraphics[width=0.3\textwidth]{45Insert.pdf}}; \\
\node [myheader]{40};&\node [myheader]{40C1};&\node [myheader]{45}; \\
\node [mylabel] {40 contacts \#20 };
&\node [mylabel] {39 contacts \#20 \\ 1 coax or triax contact \#5 \\ or 1 contact \#10};
&\node [mylabel] {45 contacts \#20};\\
\node [mynode] {};& \node [mynode]{}; &\node [mynode]{};\\

\node [mynode] {};& \node [mynode]{}; &\node [mynode]{};\\
};
\end{tikzpicture}
\end {document}
David Carlisle
  • 757,742
Yves
  • 2,825
  • Why the , in the font key (it’s not a list)? Simply declare font=\Huge\sffamily. – Qrrbrbirlbel Aug 04 '13 at 14:10
  • I have edited the font declaration as you suggested. – Yves Aug 04 '13 at 14:15
  • It works. I wonder wether I should delete my question entirely or revert the code back to the mistaken one and close it. It is not clear to me however why the declaration "font=\sf", at the "begin tikz picture" level is not sufficient to convert all fonts of the picture. – Yves Aug 04 '13 at 14:28
  • It would be better to revert your question to the erroneous version. Take a look at my updated answer where I have introduced some ways to tackle this problem differently. – Qrrbrbirlbel Aug 04 '13 at 14:52
  • I have reverted to the original mistaken version. – Yves Aug 04 '13 at 16:05

1 Answers1

1

The font key will not be processed like a list but the contents will simply be used before the node content. Simply declare

font=\Huge\sffamily

and the width of the comma will not be visible as horizontal space.

(As you may have noticed, I have also used the LaTeX macro \sffamily instead of the old TeX macro \sf, see Does it matter if I use \textit or \it, \bfseries or \bf, etc.)

On a semi-related note, take a look at the matrix library and the matrix of nodes option for the \matrix macro. With these you could simply use the node contents in the cells and define, say

row 2/.style={nodes=myheader}

If you want a cumulative font key define

\makeatletter
\tikzset{
    add font/.code=\expandafter\def\expandafter\tikz@textfont\expandafter{\tikz@textfont#1}}
\makeatother

You can now use add font=\Huge in the myheader style without repeating \sffamily.

Another idea is to use \sffamily directly in the tikzpicture environment, this can be done as a style, too:

\tikzset{set font to sf/.code=\sffamily}

or you define every picture to be in \sffamily with:

\tikzset{every picture/.append style={execute at begin picture=\sffamily}}

Code

\PassOptionsToPackage{draft}{graphicx}
\documentclass[tikz,convert=false]{standalone}
\begin{document}
\begin{tikzpicture}[
  font=\sffamily,
  mynode/.style={
    rectangle,
    text width = 4.5cm,
    anchor=north,
    inner sep=0pt},
  myheader/.style={
    rectangle,
    fill,
    color=blue!20,
    text width=4.55cm,
    text=black,
    font=\Huge\sffamily,
    inner sep=5pt},
  mylabel/.style={
    rectangle,
    fill,
    minimum height=10ex,
    color=black!10,
    text=black,
    text width=4.55cm,
    anchor=north,
    inner sep=5pt}
  ]
  \matrix [column sep=0pt, row sep=0mm, align=center, draw, rectangle]{
    \node {\includegraphics[width=0.3\textwidth]{40Insert.pdf}}; &
      \node {\includegraphics[width=0.3\textwidth]{40C1Inser.pdf}}; &
        \node {\includegraphics[width=0.3\textwidth]{45Insert.pdf}}; \\
    \node [myheader]{40}; &
      \node [myheader]{40C1}; & 
        \node [myheader]{45}; \\
    \node [mylabel] {40 contacts \#20 }; &
      \node [mylabel] {39 contacts \#20 \\ 1 coax or triax contact \#5 \\ or 1 contact \#10}; &
        \node [mylabel] {45 contacts \#20}; \\
    \node [mynode] {}; &
      \node [mynode]{}; &
        \node [mynode]{}; \\
    \node [mynode] {}; &
      \node [mynode]{}; &
        \node [mynode]{}; \\
  };
\end{tikzpicture}
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
  • Excellent. The code is much more readable and simple. I am going to change all calls for \sf, as suggested. I work on industrial documents, and virtually all fonts are sansserif – Yves Aug 04 '13 at 14:36