我使用三個迷你頁來製作一個表格和兩個圖像並排放置,儘管圖像位於正確的位置,但表格放置得更低,產生了醜陋的結果。為什麼會發生這種情況?我該如何修復它?
\begin{minipage}[t]{5cm}
\begin{tabular}{|c|c|c|}
\hline
$V_{c}(Low)$ & $mV$ & $0$\\
\hline
$V_{c}(High)$ & $V$ & $5.6$\\
\hline
$T_{d}$ & $ns$ & $30$\\
\hline
$T_{r}$ & $ns$ & $30$\\
\hline
$T_{sd}$ & $ns$ & $780$\\
\hline
$T_{f}$ & $ns$ & $240$\\
\hline
$F_{max}$ & $kHz$ & $570$\\
\hline
\end{tabular}
\end{minipage}
\begin{minipage}[t]{5cm}
\includegraphics[width=\textwidth]{A1.JPG}
\end{minipage}
\begin{minipage}[t]{5cm}
\includegraphics[width=\textwidth]{A2.JPG}
\end{minipage}
答案1
為什麼你的程式碼不起作用。
這與垂直對齊的實際工作方式有關。首先考慮以下程式碼及其輸出:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
Some text then a table \begin{tabular}{c}
1 \\2 \\ 3 \\ 4
\end{tabular}
then some more text and an image \includegraphics[width=2cm]{example-image-10x16}.
\end{document}
重點是表格和圖像相對於周圍文字的基線的放置方式——tabular
垂直居中,圖像放置在基線上,因此粘在線條上方。
現在s 的t
/b
位置說明符所指minipage
的實際上並不是 s 的頂部/底部邊緣minipage
,據我所知,而是文字第一行/最後一行的基線在裡面minipage
。在表格中minipage
,基線位於表格的中間,如上圖所示。但在minipage
影像中,基線位於影像的底部。結果,影像的底部與表格的中間對齊。
建議1
根據 daleif 的建議,我刪除了下面程式碼中的minipage
for 。tabular
如果你設定右邊的對齊方式minipage
輸入c
的話看起來會更好,即
\begin{minipage}[c]{5cm}
預設情況下具有tabular
對齊c
方式。
tabular
若要使它們頂部對齊,您可以將和minipage
s的位置設為,並將s 與影像t
的內部位置(第三個可選參數)設為。也就是說,你將擁有minipage
b
\begin{tabular}[t]{...}
對於桌子和
\begin{minipage}[t][][b]{5cm}
對於minipage
s。
建議2
如果添加,則可以使用可選參數來\usepackage[export]{adjustbox}
更改影像相對於基線的垂直對齊方式。然後你就可以完全放棄 s 了。valign=<t/c/b>
\includegraphics
minipage
\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage[export]{adjustbox}
\begin{document}
\begin{tabular}{>{$}c<{$} s S }
\toprule
V_{c}(\text{Low}) & \milli\volt & 0\\
V_{c}(\text{High}) & \volt & 5.6\\
T_{d} & \nano\s & 30\\
T_{r} & \nano\s & 30\\
T_{sd} & \nano\s & 780\\
T_{f} & \nano\s & 240\\
F_{\text{max}} & \kilo\hertz & 570\\
\bottomrule
\end{tabular}\hspace{1em}
\includegraphics[width=5cm,valign=c]{example-image-a}
\includegraphics[width=5cm,valign=c]{example-image-b}
\end{document}
關於該表的一些註解。
並不是問題的一部分,但我添加了關於如何在下面的程式碼中編寫表格的建議,您可以在圖像中看到結果。
列規格已變更為{>{$}c<{$} s S }
。載入array
套件時,您可以使用>{}
/<{}
在儲存格的開頭/結尾插入內容,透過執行上述操作,效果是每個儲存格都設定為數學模式。這可以節省您一些打字時間。
對於第二列,請注意單位通常不應以斜體書寫。你可以簡單地刪除所有數學模式,這樣會好很多。這裡我使用了s
from 的一列siunitx
,它允許使用單位宏 fromsiunitx
來排版單位。
最後一列S
也是來自 的一列siunitx
,它將數字與小數點標記對齊。不確定在這種情況下是否有所改進,但我想我會將其添加為提示。
在第一列中,您會注意到我在文字模式下設定了單字「低」、「高」和「最大」。我認為這主要是一個約定問題,但我認為與變數名稱相反,描述性單字不應該是斜體。我還刪除了所有垂直線,並booktabs
在上方和下方添加了一條較粗的水平線(來自)。它使桌子不再那麼混亂。
\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{>{$}c<{$} s S }
\toprule
V_{c}(\text{Low}) & \milli\volt & 0\\
V_{c}(\text{High}) & \volt & 5.6\\
T_{d} & \nano\s & 30\\
T_{r} & \nano\s & 30\\
T_{sd} & \nano\s & 780\\
T_{f} & \nano\s & 240\\
F_{\text{max}} & \kilo\hertz & 570\\
\bottomrule
\end{tabular}\hspace{1em}
\begin{minipage}[c]{5cm}
\includegraphics[width=\textwidth]{example-image-a}
\end{minipage}
\begin{minipage}[c]{5cm}
\includegraphics[width=\textwidth]{example-image-b}
\end{minipage}
\vspace{2cm}
\begin{tabular}[t]{>{$}c<{$} s S }
\toprule
V_{c}(\text{Low}) & \milli\volt & 0\\
V_{c}(\text{High}) & \volt & 5.6\\
T_{d} & \nano\s & 30\\
T_{r} & \nano\s & 30\\
T_{sd} & \nano\s & 780\\
T_{f} & \nano\s & 240\\
F_{\text{max}} & \kilo\hertz & 570\\
\bottomrule
\end{tabular}\hspace{1em}
\begin{minipage}[t][][b]{5cm}
\includegraphics[width=\textwidth]{example-image-a}
\end{minipage}
\begin{minipage}[t][][b]{5cm}
\includegraphics[width=\textwidth]{example-image-b}
\end{minipage}
\end{document}
答案2
人們可以完全避免包裝的minipages
使用\abovebaseline
和使用。請注意 MWE 末尾的語法。在這種情況下,我將每個項目保存在自己的堆疊框中,以便如果需要居中輸出,則需要使用框高度進行額外計算。否則,可以使用所示語法直接輸出列。\belowbaseline
stackengine
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{stackengine}
\parskip 1em
\begin{document}
\savestack{\colA}{
\begin{tabular}[b]{|c|c|c|}
\hline
$V_{c}(Low)$ & $mV$ & $0$\\
\hline
$V_{c}(High)$ & $V$ & $5.6$\\
\hline
$T_{d}$ & $ns$ & $30$\\
\hline
$T_{r}$ & $ns$ & $30$\\
\hline
$T_{sd}$ & $ns$ & $780$\\
\hline
$T_{f}$ & $ns$ & $240$\\
\hline
$F_{max}$ & $kHz$ & $570$\\
\hline
\end{tabular}}
\savestack{\colB}{\includegraphics[width=5cm,height=4cm]{A1.JPG}}
\savestack{\colC}{\includegraphics[width=5cm,height=2.5cm]{A2.JPG}}
\colA\ \abovebaseline[.5\ht\colAcontent-.5\ht\colBcontent]{\colB}\
\abovebaseline[.5\ht\colAcontent-.5\ht\colCcontent]{\colC}
\colA\ \colB\ \colC
\belowbaseline{\colA}\ \belowbaseline{\colB}\ \belowbaseline{\colC}
\end{document}
答案3
tabular
已經是一種小型頁面(您可能想使用\begin{tabular[t]{...}
)。預設情況下,它的基線位於中間,周圍minipage
不會改變這一點,因為它tabular
的行為就像一條線(有點)。這些圖像在底座上對齊,並且它比底座更高。
您可能想要使用該adjustbox
軟體包,它具有許多用於對齊內容的有用功能。
還有一個小請求:請發布一些我們可以複製貼上並使用而無需編輯的內容。您沒有序言,我們當然也沒有您的圖像。對於圖像,您可以使用\rule{length}{length}
.