[英]Vertical Alignment of text in a table in Latex (Overleaf)
我在背面有以下示例代碼來生成表格。
\documentclass[hidelinks,a4paper,12pt,oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\usepackage{stackengine}
\newcommand\xrowht[2][0]{\addstackgap[0.5\dimexpr#2\relax]{\vphantom{#1}}}
\title{table}
\begin{document}
\maketitle
\begin{table}[ht]
\footnotesize
\centering
\begin{tabular}{|P{0.75cm}|P{1.25cm}|P{0.75cm}|P{0.75cm}|P{0.75cm}|P{0.75cm}|P{0.75cm}|P{1cm}|P{1cm}|P{1cm}|P{1cm}|P{0.75cm}|}
\hline\xrowht[()]{15pt}
\multirow{2}{*}{Test} & \multirow{2}{*}{Name} & \multicolumn{3}{c|}{Domain} & \multirow{2}{*}{Cell} & \multicolumn{4}{c|}{MLR} & \multirow{2}{*}{$C_1$} & \multirow{2}{*}{$C_2$}\\
\cline{3-5}\cline{7-10}\xrowht[()]{15pt}
No & & x & y & z & Size & $\dot{m_t}$ & $\dot{m}_{in}$ & $\dot{m}_{out}$ & $\dot{m}_{avg}$ & & \\
\hline\xrowht[()]{15pt}
1 & Mass1 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 \\
\hline\xrowht[()]{15pt}
2 & Mass2 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 & \multicolumn{2}{c|}{0.1} & 0.1 & 0.1 & 0.1 \\
\hline
\end{tabular}
\vspace{0.5cm}
\caption{Tests}
\end{table}
\end{document}
這給了我,
問題:我無法讓表格內的文本垂直對齊到中心或任何其他 position 。 例如,文本“Test No”、“Name”、“Cell Size”、“C1”和“C2”應該垂直居中對齊。 此外,我看到使用\hline\xrowht[()]{15pt}
給了我不同的框寬度,請參閱 "Domain" 和 "MLR" 框。 有人可以幫我以正確的方式設置這張桌子嗎?
感謝大家
而不是手動弄亂表格的行高,您可以更改\arraystretch
並且您的所有單元格將自動居中
其他幾點:
不要在標題上方手動添加空格,而是查看caption
package
please have a look at http://betterposters.blogspot.com/2012/08/the-data-prison.html or https://www.inf.ethz.ch/personal/markusp/teaching/guides/guide-tables .pdf獲取一些關於漂亮表格布局的指南。 將你的數據投入監獄絕對不是一個好的設計
不要將多字母表達式(如avg
或out
)置於數學模式中。 這將完全弄亂字距
\documentclass[hidelinks,a4paper,12pt,oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\usepackage{caption}
\title{table}
\begin{document}
\maketitle
\begin{table}[ht]
\renewcommand{\arraystretch}{2}
\footnotesize
\centering
\begin{tabular}{|P{0.75cm}|P{1.25cm}|P{0.75cm}|P{0.75cm}|P{0.75cm}|P{0.75cm}|P{0.75cm}|P{1cm}|P{1cm}|P{1cm}|P{1cm}|P{0.75cm}|}
\hline
\multirow{2}{0.75cm}{\centering Test\\ No} & \multirow{2}{*}{Name} & \multicolumn{3}{c|}{Domain} & \multirow{2}{0.75cm}{\centering Cell\\ Size} & \multicolumn{4}{c|}{MLR} & \multirow{2}{*}{$C_1$} & \multirow{2}{*}{$C_2$}\\
\cline{3-5}\cline{7-10}
& & x & y & z & & $\dot{m_t}$ & $\dot{m}_{in}$ & $\dot{m}_{out}$ & $\dot{m}_{avg}$ & & \\
\hline
1 & Mass1 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 \\
\hline
2 & Mass2 & 0.1 & 0.1 & 0.1 & 0.1 & 0.1 & \multicolumn{2}{c|}{0.1} & 0.1 & 0.1 & 0.1 \\
\hline
\end{tabular}
% \vspace{0.5cm}
\caption{Tests}
\end{table}
\end{document}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.