2

I would like a table and circuitikz diagram to appear to the left and right of one another, but I can't seem to get it to work with subfigures or subtables. What gives? Here's one of the ways I tried to get it to work. The table just ends up below the diagram.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{circuitikz}

\usepackage[cm]{fullpage}

\begin{document}

\begin{table}[h]
\centering
 \begin{subtable}[b]{0.5\textwidth}
  \begin{circuitikz} \draw
(0,-1) to[battery] (0,2)
      to[ammeter] (4,2) -- (4,-1)
      to[resistor] (0,-1)
(0.5,-1) -- (0.5,-2)
      to[voltmeter] (3.5,-2) -- (3.5,-1)
;
\end{circuitikz}
\end{subtable}%
\qquad
\begin{subtable}[b]{0.5\textwidth}
\begin{tabular}{@{}cc@{}}
\toprule
Current & Voltage Drop \\
(mA)    & (mV)         \\ \midrule
500     & 198          \\
1000    & 381          \\
1500    & 581          \\
2000    & 824          \\
2500    & 904          \\
3000    & 1169         \\ \bottomrule
\end{tabular}
\end{subtable}
\end{table}

\end{document}

3 Answers3

2

By default, images align (have their baseline) on the bottoms and tabulars are centered. Both can be adjusted internally, or one can use \raisebox. The following aligned their centers. Also, \hfil and \vfil is how centering is actually done.

align table

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{circuitikz}

\usepackage[cm]{fullpage}

\begin{document}
\null\vfil% ceneter vertically
\noindent\rule{\textwidth}{1pt}% reference
\begin{table}[h]
\hfil\raisebox{-0.5\height}{%
  \begin{circuitikz} \draw
(0,-1) to[battery] (0,2)
      to[ammeter] (4,2) -- (4,-1)
      to[resistor] (0,-1)
(0.5,-1) -- (0.5,-2)
      to[voltmeter] (3.5,-2) -- (3.5,-1)
;
\end{circuitikz}}
\hfil%
\begin{tabular}[c]{@{}cc@{}}
\toprule
Current & Voltage Drop \\
(mA)    & (mV)         \\ \midrule
500     & 198          \\
1000    & 381          \\
1500    & 581          \\
2000    & 824          \\
2500    & 904          \\
3000    & 1169         \\ \bottomrule
\end{tabular}
\end{table}

\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120
2

There are two things you can do. Make the tabular align at the baseline too (like the image does by default) by using

 \begin{tabular}[b]{@{}cc@{}}    %% note [b]

enter image description here

Or align the circuit at the center of its bounding box (like the tabular does by default, you don't need to put [c] BTW):

\begin{circuitikz}[baseline={(current bounding box.center)}]

enter image description here

This is more tikzish way of vertically centering.

Full code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{circuitikz}

\usepackage[cm]{fullpage}

\begin{document}
\null\vfil% ceneter vertically
\noindent\rule{\textwidth}{1pt}% reference
\begin{table}[h]
\hfil
  \begin{circuitikz}[baseline={(current bounding box.center)}]
  \draw
(0,-1) to[battery] (0,2)
      to[ammeter] (4,2) -- (4,-1)
      to[resistor] (0,-1)
(0.5,-1) -- (0.5,-2)
      to[voltmeter] (3.5,-2) -- (3.5,-1)
;
\end{circuitikz}
\hfil%
\begin{tabular}{@{}cc@{}}       %% or use [b] position specifier as for the first case
\toprule
Current & Voltage Drop \\
(mA)    & (mV)         \\ \midrule
500     & 198          \\
1000    & 381          \\
1500    & 581          \\
2000    & 824          \\
2500    & 904          \\
3000    & 1169         \\ \bottomrule
\end{tabular}
\end{table}

\end{document}
1

The subtable makes no sense here if you want it on top of each other. This is centered:

\begin{table}[!htb]
\centering
\begin{circuitikz} \draw
(0,-1) to[battery] (0,2)
      to[ammeter] (4,2) -- (4,-1)
      to[resistor] (0,-1)
(0.5,-1) -- (0.5,-2)
      to[voltmeter] (3.5,-2) -- (3.5,-1)
;
\end{circuitikz}

\begin{tabular}{@{}cc@{}}
\toprule
Current & Voltage Drop \\
(mA)    & (mV)         \\ \midrule
500     & 198          \\
1000    & 381          \\
1500    & 581          \\
2000    & 824          \\
2500    & 904          \\
3000    & 1169         \\ \bottomrule
\end{tabular}
\end{table}