テーブルで少し問題があります。テーブルのコードは次のようになります。
\documentclass{report}
\usepackage{booktabs}
\usepackage{array}
\newcommand*\rotbf[1]{\rotatebox{90}{\textbf{#1}}}
\newcommand{\specialcell}[2][c]{\begin{tabular}[#1]{@{}l@{}}#2\end{tabular}}
\begin{document}
\begin{table}[hbr]
\centering
\label{tbl:heatwheel_res}
\begin{tabular}{llll}
\toprule
\textbf{Parameter} & \specialcell{Exhaust\\air} & \specialcell{Exhaust and \\ outdoor air} & \specialcell{Heat wheel\\(80~\%)} \\
\midrule
Heat recovery [\%] & 89,6 \% & 89,6 \% & 77,4 \% \\
Real heat recovery [\%] & 50,5 \% & 52,1 \% & - \\
Net energy need for VH and SH & 27,7 & 27,0 & 15,8 \\
\specialcell{Delivered energy for\\DHW, VH and SH} & 31,1 & 27,6 & 45,6 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
\specialcell
長すぎる要素の行を分割するためにを使用しています。ただし、最初の行のテキストを太字にしたいのです。\textbf{}
内部に追加すると\specialcell
、ドキュメントがコンパイルされません。エラー メッセージは「 」ですMissing } inserted
。
何か提案はありますか?\specialcell2
自動的に太字になる新しい特殊セル ( ) を作成できますか?
もう 1 つ質問があります。最初の列と 2 番目の列の間のスペースを増やすために、テーブルを少し広くするにはどうすればよいでしょうか。行 4 では列 1 と列 2 が少し近すぎると思います。
答え1
\specialcell
太字にする必要がある外側のセル全体を\bfseries
外側のセルで指定できるため、次の直前で指定できます\specialcell
。
... & \bfseries\specialcell{...} & ...
これをマクロに組み込むこともできます\specialcellbold
。次の例を参照してください。
\documentclass{report}
\usepackage{booktabs}
\usepackage{array}
\newcommand*\rotbf[1]{\rotatebox{90}{\textbf{#1}}}
\newcommand{\specialcell}[2][c]{\begin{tabular}[#1]{@{}l@{}}#2\end{tabular}}
\newcommand{\specialcellbold}[2][c]{%
\bfseries
\begin{tabular}[#1]{@{}l@{}}#2\end{tabular}%
}
\begin{document}
\begin{table}[hbr]
\centering
\label{tbl:heatwheel_res}
\begin{tabular}{llll}
\toprule
\textbf{Parameter} &
\specialcellbold{Exhaust\\air} &
\specialcellbold{Exhaust and\\ outdoor air} &
\specialcellbold{Heat wheel\\(80~\%)} \\
\midrule
Heat recovery [\%] & 89,6 \% & 89,6 \% & 77,4 \% \\
Real heat recovery [\%] & 50,5 \% & 52,1 \% & - \\
Net energy need for VH and SH & 27,7 & 27,0 & 15,8 \\
\specialcell{Delivered energy for\\DHW, VH and SH} & 31,1 & 27,6 & 45,6 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
表のフォーマットは少し異なります:
\documentclass{report}
\usepackage{booktabs}
% \usepackage{array}% It can also be loaded explicitly, implicitly it is
% loaded by siunitx
\usepackage{siunitx}
% \sisetup{output-decimal-marker={,}}% OP now wants to have the default dot
\sisetup{detect-weight, mode=text}
\newcommand*\rotbf[1]{\rotatebox{90}{\textbf{#1}}}
\newcommand{\specialcell}[2][b]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\newcommand{\specialcellbold}[2][b]{%
\bfseries
\sisetup{text-rm=\bfseries}%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}%
}
\newcommand*{\leftspecialcell}[2][b]{%
\begin{tabular}[#1]{@{}l@{}}#2\end{tabular}%
}
\begin{document}
\begin{table}[hbr]
\centering
\label{tbl:heatwheel_res}
\begin{tabular}{l*{3}{S[table-format=2.1]}}
\toprule
\textbf{Parameter} &
{\specialcellbold{Exhaust\\air}} &
{\specialcellbold{Exhaust and\\ outdoor air}} &
{\specialcellbold{Heat wheel\\(\SI{80}{\percent})}} \\
\midrule
Heat recovery [\si{\percent}] & 89,6 & 89,6 & 77,4 \\
Real heat recovery [\si{\percent}] & 50,5 & 52,1 & {---} \\
Net energy need for VH and SH & 27,7 & 27,0 & 15,8 \\
\leftspecialcell{Delivered energy for\\
\quad DHW, VH and SH} & 31,1 & 27,6 & 45,6 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
備考:
- 下揃えのヘッダー行。
- 2列目から4列目は中央揃えになります。
- パッケージの使用
siunitx
小数点の位置合わせとパーセント記号の設定に使用します。 - 左のセルの最初の行の後の行はインデントされ、配置は垂直方向の中央揃えではなく、下の行に従います。
- 欠落しているエントリにはハイフンの代わりに em ダッシュを使用します。
- 冗長なパーセント記号が削除されました。
- 出力小数点をデフォルトのドットに変更しました(コメントROLFの)。
- 少し粗雑です
\siunit{text-rm=\bfseries}
。オプションは-columndetect-weight
内では機能しませんでしたS
。
アップデート
私、Svend Tveskæg は、コードが読みにくいと感じたので、少し整理しました (問題ないと思います):
\documentclass{report}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{
% output-decimal-marker = {,},
detect-weight,
mode = text
}
\newcommand*{\specialcell}[2][b]{%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}%
}
\newcommand*{\specialcellbold}[2][b]{%
\bfseries
\sisetup{text-rm = \bfseries}%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}%
}
\newcommand*{\leftspecialcell}[2][b]{%
\begin{tabular}[#1]{@{}l@{}}#2\end{tabular}%
}
\begin{document}
\begin{table}[htbp]
\centering
\label{tbl:heatwheel-res}
\begin{tabular}{l *{3}{S[table-format = 2.1]}}
\toprule
\textbf{Parameter} &
{\specialcellbold{Exhaust \\ air}} &
{\specialcellbold{Exhaust and\\ outdoor air}} &
{\specialcellbold{Heat wheel \\ (\SI{80}{\percent})}} \\
\midrule
Heat recovery [\si{\percent}] & 89,6 & 89,6 & 77,4 \\
Real heat recovery [\si{\percent}] & 50,5 & 52,1 & {---} \\
Net energy need for VH and SH & 27,7 & 27,0 & 15,8 \\
\leftspecialcell{Delivered energy for \\
\quad DHW, VH and SH} & 31,1 & 27,6 & 45,6 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答え2
比較のためだけに。この表をプレーン TeX で作成する方法。ただし、LaTeX (パッケージをロードしなくても) でも機能します。
\def\toprule{\noalign{\medskip\hrule height .8pt\medskip}}
\def\midrule{\noalign{\medskip\hrule\medskip}}
\let\bottomrule=\toprule
\def\specialcell#1{$\vcenter{\halign{\hfil##\hfil\strut\cr#1\cr}}$}
\def\x{\phantom{\%}}\def\h{\hfill\null}
\halign{&\ \hfil#\unskip\ \hfil\cr
\toprule
\bf Parameter\h & \bf\specialcell{Exhaust\cr air} &
\bf\specialcell{Exhaust and\cr outdoor air} &
\bf\specialcell{Heat wheel\cr(80~\%)} \cr
\midrule
Heat recovery [\%]\h &89,6 \% & 89,6 \% & 77,4 \% \cr
Real heat recovery [\%]\h & 50,5 \% & 52,1 \% & --- \cr
Net energy need for VH and SH & 27,7 \x & 27,0 \x & 15,8 \x \cr
\specialcell{Delivered energy for\cr DHW, VH and SH\hfill}\h& 31,1 \x & 27,6 \x & 45,6 \x\cr
\bottomrule
}
\bye
答え3
車輪の再発明はしないでください:makecell
パッケージ:\thead
および\makecell
コマンドにより、セル内の改行と共通の書式設定が可能になります。また、 パッケージをロードすると、\rothead
およびコマンドも定義されます。デモ:\rotcell
rotating
\documentclass{report}
\usepackage{booktabs}
\usepackage{array}
\usepackage{rotating}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}
\renewcommand\cellalign{lc}
\setcellgapes{2pt}
\makegapedcells
\begin{document}
\begin{table}[hbr]
\centering
\label{tbl:heatwheel_res}
\begin{tabular}{lccc}
\toprule
\makecell{\bfseries Parameter} & \thead{Exhaust\\air} & \thead{Exhaust and \\ outdoor air} & \thead{Heat wheel\\(80~\%)} \\
\midrule
\makecell{Heat recovery\\{}[\%]} & 89,6 & 89,6 & 77,4 \\
\makecell{Real heat recovery\\{}[\%]} & 50,5 & 52,1 & -- \\
\makecell{Net energy need for\\VH and SH} & 27,7 & 27,0 & 15,8 \\
\makecell{Delivered energy for\\DHW, VH and SH} & \rotcell{31,1 }& 27,6 & 45,6 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}