1

I'm tryin to vertically center a tikzpicture in a table. Here's a not-very-minimal example:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc} % UFT8 - danske bogstaver og andet godt fra havet
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{amsmath} % noget matematik
\usepackage{amssymb} % mere matematik
\usepackage[a4paper,margin=1in]{geometry} % andre margener og andet gøgl
\begin{document}

\begin{tabularx}{\textwidth}{lXcc}
\toprule
\textbf{Type} & \textbf{Hvilke} & \textbf{Tegning} & \textbf{CFSE} \\
\midrule
Plankvadratisk & Generelt i 5. og 6. periode og nikkel. Har 4 bindinger til ligander & 

\begin{tikzpicture}[scale=0.2, line width=1pt]

\draw (0,0) -- (3,0);
\draw (4,0) -- (7,0);

\draw (2,1.5) -- (5,1.5);
\draw (2,3) -- (5,3);
\draw (2,4.5) -- (5,4.5);

\end{tikzpicture}

\\
\\

Tetraedrisk & Generelt i 4. periode på nær nikkel. Har 4 bindinger til ligander & 

\begin{tikzpicture}[scale=0.2, line width=1pt]

\draw (0,0) -- (3,0);
\draw (4,0) -- (7,0);

\draw (2,1.5) -- (5,1.5);
\draw (6,1.5) -- (9,1.5);
\draw (-2,1.5) -- (1,1.5);

\end{tikzpicture}

& CFSE $= \left(-\frac{3}{5} \cdot e^- + \frac{2}{5} \cdot e^-\right)\Delta_{\text{tet}}$ \\\\
Octaedrisk & Har 6 bindinger til ligander & 
%\includegraphics[scale=0.40]{oct.png} 

\begin{tikzpicture}[scale=0.2, line width=1pt]

\draw (0,0) -- (3,0);
\draw (4,0) -- (7,0);
\draw (8,0) -- (11,0);
\draw (2,1.5) -- (5,1.5);
\draw (6,1.5) -- (9,1.5);

\end{tikzpicture}

& CFSE $= \left(-\frac{2}{5} \cdot e^- + \frac{3}{5} \cdot e^-\right)\Delta_{\text{oct}}$ \\
\bottomrule
\end{tabularx}

\end{document}

Which gives this:

enter image description here

I'd like to vertically center these tikzpictures in the cells.

1

Rather than trying to auto-center the tikz images, it is simpler to just apply a \raisebox to each tikz.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc} % UFT8 - danske bogstaver og andet godt fra havet
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{amsmath} % noget matematik
\usepackage{amssymb} % mere matematik
\usepackage[a4paper,margin=1in]{geometry} % andre margener og andet gøgl
\begin{document}

\begin{tabularx}{\textwidth}{lXcc}
\toprule
\textbf{Type} & \textbf{Hvilke} & \textbf{Tegning} & \textbf{CFSE} \\
\midrule
Plankvadratisk & Generelt i 5. og 6. periode og nikkel. Har 4 bindinger til ligander & 

\raisebox{-30pt}{\begin{tikzpicture}[scale=0.2, line width=1pt]

\draw (0,0) -- (3,0);
\draw (4,0) -- (7,0);

\draw (2,1.5) -- (5,1.5);
\draw (2,3) -- (5,3);
\draw (2,4.5) -- (5,4.5);

\end{tikzpicture}}

\\
\\

Tetraedrisk & Generelt i 4. periode på nær nikkel. Har 4 bindinger til ligander & 

\raisebox{-15pt}{\begin{tikzpicture}[scale=0.2, line width=1pt]

\draw (0,0) -- (3,0);
\draw (4,0) -- (7,0);

\draw (2,1.5) -- (5,1.5);
\draw (6,1.5) -- (9,1.5);
\draw (-2,1.5) -- (1,1.5);

\end{tikzpicture}}

& CFSE $= \left(-\frac{3}{5} \cdot e^- + \frac{2}{5} \cdot e^-\right)\Delta_{\text{tet}}$ \\\\
Octaedrisk & Har 6 bindinger til ligander & 
%\includegraphics[scale=0.40]{oct.png} 

\raisebox{-10pt}{\begin{tikzpicture}[scale=0.2, line width=1pt]

\draw (0,0) -- (3,0);
\draw (4,0) -- (7,0);
\draw (8,0) -- (11,0);
\draw (2,1.5) -- (5,1.5);
\draw (6,1.5) -- (9,1.5);

\end{tikzpicture}}

& CFSE $= \left(-\frac{2}{5} \cdot e^- + \frac{3}{5} \cdot e^-\right)\Delta_{\text{oct}}$ \\
\bottomrule
\end{tabularx}

\end{document}

enter image description here

1

For a Tikz based solution, you can use the baseline option to align the pictures to their north anchor in a somewhat automatic way. I've marked the new code with "new code":

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc} % UFT8 - danske bogstaver og andet godt fra havet
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{amsmath} % noget matematik
\usepackage{amssymb} % mere matematik
\usepackage[a4paper,margin=1in]{geometry} % andre margener og andet gøgl
\begin{document}

\begin{tabularx}{\textwidth}{lXcc}
\toprule
\textbf{Type} & \textbf{Hvilke} & \textbf{Tegning} & \textbf{CFSE} \\
\midrule
Plankvadratisk & Generelt i 5. og 6. periode og nikkel. Har 4 bindinger til ligander & 

\begin{tikzpicture}[scale=0.2, line width=1pt,baseline=(current bounding box.north)]  %new code
]

\draw (0,0) -- (3,0);
\draw (4,0) -- (7,0);

\draw (2,1.5) -- (5,1.5);
\draw (2,3) -- (5,3);
\draw (2,4.5) -- (5,4.5);

\end{tikzpicture}

\\
\\

Tetraedrisk & Generelt i 4. periode på nær nikkel. Har 4 bindinger til ligander & 

\begin{tikzpicture}[scale=0.2, line width=1pt,baseline=(current bounding box.north)] %new code

\draw (0,0) -- (3,0);
\draw (4,0) -- (7,0);

\draw (2,1.5) -- (5,1.5);
\draw (6,1.5) -- (9,1.5);
\draw (-2,1.5) -- (1,1.5);

\end{tikzpicture}

& CFSE $= \left(-\frac{3}{5} \cdot e^- + \frac{2}{5} \cdot e^-\right)\Delta_{\text{tet}}$ \\\\
Octaedrisk & Har 6 bindinger til ligander & 
%\includegraphics[scale=0.40]{oct.png} 

\begin{tikzpicture}[scale=0.2, baseline=(current bounding box.north)] %new code

\draw (0,0) -- (3,0);
\draw (4,0) -- (7,0);
\draw (8,0) -- (11,0);
\draw (2,1.5) -- (5,1.5);
\draw (6,1.5) -- (9,1.5);

\end{tikzpicture}

& CFSE $= \left(-\frac{2}{5} \cdot e^- + \frac{3}{5} \cdot e^-\right)\Delta_{\text{oct}}$ \\
\bottomrule
\end{tabularx}

\end{document}

enter image description here

If you are unhappy with the "automatic" vertical alignment (for example in the second row) you can still specify a custom baseline value, like baseline=15pt or whatever you like.

enter image description here

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.