我需要在两个表格单元格中换行。但是,当单元格 (1,1) 和 (1,3) 中的文本正确换行后,表格中第一行的文本却没有对齐。
\documentclass[b5paper, 10pt, twoside]{report}
\usepackage{booktabs}
\usepackage{array}
\newcommand*\rotbf[1]{\rotatebox{90}{\textbf{#1}}}
\newcommand{\specialcell}[2][b]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\newcommand{\specialcellbold}[2][b]{%
\bfseries
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}%
}
\newcommand*{\leftspecialcell}[2][b]{%
\begin{tabular}[#1]{@{}l@{}}#2\end{tabular}%
}
\newcommand*{\rightspecialcell}[2][t]{%
\begin{tabular}[#1]{@{}r@{}}#2\end{tabular}%
}
\begin{document}
\begin{table}[hbr]
\begin{tabular}{lrrrr}
\toprule \textbf{} & \textbf{NIBE} & \textbf{Nilan}& \textbf{Enervent} & \textbf{Viessman} \\
\midrule
\leftspecialcell{Heat exchanger \\ \quad type} & None & \rightspecialcell{Polystyrene\\plate exch.} & f & a \\
Heat source(s) & EA & EA & f & f \\
Heat sink(s) & Water & Water and air & f & f \\
Cooling option & No & Yes & & \\
\bottomrule
\end{tabular}\\
\end{table}
\end{document}
答案1
这使用了一种新的列类型(但也可以切换到p
- 类型)来进行包装。
\documentclass[b5paper, 10pt, twoside]{report}
\usepackage{booktabs}
\usepackage{array}
\usepackage{ragged2e}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcommand*\rotbf[1]{\rotatebox{90}{\textbf{#1}}}
\newcommand{\specialcell}[2][b]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\newcommand{\specialcellbold}[2][b]{%
\bfseries
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}%
}
\newcommand*{\leftspecialcell}[2][b]{%
\begin{tabular}[#1]{@{}l@{}}#2\end{tabular}%
}
\newcommand*{\rightspecialcell}[2][t]{%
\begin{tabular}[#1]{@{}r@{}}#2\end{tabular}%
}
\begin{document}
\begin{table}[hbr]
\caption{Some caption}\label{tbl:intflow}
\begin{tabular}{L{3cm}*{4}{r}}
\toprule \textbf{} & \textbf{NIBE} & \textbf{Nilan}& \textbf{Enervent} & \textbf{Viessman} \\
\midrule
Heat exchanger type & None & \multicolumn{1}{L{2cm}}{Polystyrene plate exch.} & f & a \\
Heat source(s) & EA & EA & f & f \\
Heat sink(s) & Water & Water and air & f & f \\
Cooling option & No & Yes & & \\
\bottomrule
\end{tabular}\\
\end{table}
\begin{table}[hbr]
\label{tbl:intflowold}
\begin{tabular}{lrrrr}
\toprule \textbf{} & \textbf{NIBE} & \textbf{Nilan}& \textbf{Enervent} & \textbf{Viessman} \\
\midrule
\leftspecialcell{Heat exchanger \\ \quad type} & None & \rightspecialcell{Polystyrene\\plate exch.} & f & a \\
Heat source(s) & EA & EA & f & f \\
Heat sink(s) & Water & Water and air & f & f \\
Cooling option & No & Yes & & \\
\bottomrule
\end{tabular}\\
\end{table}
\end{document}