我希望表格和电路图彼此显示在左右两侧,但似乎无法使其与子图或子表配合使用。这是怎么回事?这是我尝试使其工作的方法之一。表格最终位于图表下方。
\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}
答案1
默认情况下,图像对齐(基线对齐)在底部,表格居中。两者都可以内部调整,或者可以使用 \raisebox。以下对齐它们的中心。此外,\hfil 和 \vfil 是实际居中的方式。
\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}
答案2
你可以做两件事。tabular
使用以下方法使对齐也与基线对齐(就像图像默认所做的那样)
\begin{tabular}[b]{@{}cc@{}} %% note [b]
或者将电路对齐到其边界框的中心(就像tabular
默认情况下那样,您不需要放置[c]
BTW):
\begin{circuitikz}[baseline={(current bounding box.center)}]
这是更tikz
垂直居中的方式。
完整代码:
\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}
答案3
如果您希望子表相互重叠,则子表在这里毫无意义。这是居中的:
\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}