我有以下示例代码
\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{dcolumn}
\usepackage{tabularx}
\usepackage{multirow}
\DeclareMathVersion{nxbold}
\SetSymbolFont{operators}{nxbold}{OT1}{cmr} {b}{n}
\SetSymbolFont{letters} {nxbold}{OML}{cmm} {b}{it}
\SetSymbolFont{symbols} {nxbold}{OMS}{cmsy}{b}{n}
\begin{document}
\newcolumntype{d}[1]{D{,}{,}{#1}}
\makeatletter
\newcolumntype{B}[3]{>{\mathversion{nxbold}\DC@{#1}{#2}{#3}}c<{\DC@end}}
\newcolumntype{U}[3]{>{<<what to put here for underline cell?>>\DC@{#1}{#2}{#3}}c<{\DC@end}}
\makeatother
\begin{table}[htbp]
\begin{center}
\begin{tabularx}{\textwidth}{d{2.3}d{2.3}}
\multicolumn{1}{c}{bold}& \multicolumn{1}{c}{underlined} \\
\multicolumn{1}{B{,}{,}{6.2}}{12,345} & \multicolumn{1}{U{,}{,}{6.2}}{56,789} \\
\end{tabularx}
\end{center}
\end{table}
粗体数学类型B
取自Z
这里并且运行完美。
我必须在U
类型中输入什么<<what to put here for underline cell?>>
才能获得带下划线的单元格?
我已经尝试\underline
过从包\uline
中获取信息ulem
,但都导致错误。这个dcolumn
包能解决这个问题吗?
感谢您的帮助
答案1
我建议使用提供命令collcell
的包。您将这些命令放入列定义中。\collectcell
\endcollectcell
U
\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{dcolumn}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{collcell}
\DeclareMathVersion{nxbold}
\SetSymbolFont{operators}{nxbold}{OT1}{cmr} {b}{n}
\SetSymbolFont{letters} {nxbold}{OML}{cmm} {b}{it}
\SetSymbolFont{symbols} {nxbold}{OMS}{cmsy}{b}{n}
\newcolumntype{d}[1]{D{,}{,}{#1}}
\makeatletter
\newcolumntype{B}[3]{>{\mathversion{nxbold}\DC@{#1}{#2}{#3}}c<{\DC@end}}
\newcolumntype{U}[3]{>{\collectcell\underline\DC@{#1}{#2}{#3}}c<{\DC@end\endcollectcell}}
\makeatother
\begin{document}
\begin{table}[htbp]
\begin{center}
\begin{tabularx}{\textwidth}{d{2.3}d{2.3}}
\multicolumn{1}{c}{bold}& \multicolumn{1}{c}{underlined} \\
\multicolumn{1}{B{,}{,}{2.3}}{12,345} & \multicolumn{1}{U{,}{,}{2.3}}{56,789} \\
\end{tabularx}
\end{center}
\end{table}
\end{document}
编辑此版本不需要collcell
包
\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{dcolumn}
\usepackage{tabularx}
\usepackage{multirow}
\DeclareMathVersion{nxbold}
\SetSymbolFont{operators}{nxbold}{OT1}{cmr} {b}{n}
\SetSymbolFont{letters} {nxbold}{OML}{cmm} {b}{it}
\SetSymbolFont{symbols} {nxbold}{OMS}{cmsy}{b}{n}
\newcolumntype{d}[1]{D{,}{,}{#1}}
\makeatletter
\newcolumntype{B}[3]{>{\mathversion{nxbold}\DC@{#1}{#2}{#3}}c<{\DC@end}}
\newcolumntype{U}[3]{>{$\@@underline\bgroup\hbox\bgroup\DC@{#1}{#2}{#3}}c<{\DC@end\egroup\egroup\m@th$}}
\makeatother
\begin{document}
\meaning\underline{Roba varia e eventuale}
\begin{table}[htbp]
\begin{center}
\begin{tabularx}{\textwidth}{d{2.3}d{2.3}}
\multicolumn{1}{c}{bold}& \multicolumn{1}{c}{underlined} \\
\multicolumn{1}{B{,}{,}{2.3}}{12,345} & \multicolumn{1}{U{,}{,}{2.3}}{56,789} \\
\end{tabularx}
\end{center}
\end{table}
\end{document}
答案2
siunitx
这是另一种我更习惯的(不完整)方法。对于粗体列,我设法让它工作。对于下划线,仅在一列中出现一次似乎有效。请参阅我的评论,了解我遇到的问题。
% arara: pdflatex
\documentclass[12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} % if you do not want to stay with pixeled characters
\usepackage{siunitx}
\sisetup{output-decimal-marker = {,}} % or you set the localisation for your language e.g. 'locale = FR'
\usepackage[normalem]{ulem}
\usepackage{etoolbox}
\robustify\bfseries
\robustify\uline
\newcolumntype{B}[1]{>{\bfseries}S[table-format=#1, detect-weight]}
%\usepackage{collcell}
%\newcolumntype{U}[1]{>{\collectcell\uline}{S[table-format=#1]}<{\endcollectcell}} % does not work. It seems as if collcell can just handle standard column types.
\begin{document}
\begin{table}[h] % h just for demo. Do not use it...
\centering
\begin{tabular}{S[table-format=2.3, detect-weight]S[table-format=2.3]}
{bold} & {underlined} \\
\bfseries 12,345 & \uline{56,789} \\
\end{tabular}
\end{table}
\begin{table}[h]
\centering
\begin{tabular}{B{2.3}S[table-format=2.3]} % using \uline for all entries is a not solved problem still. See here http://tex.stackexchange.com/q/161032
{\normalfont bold} & {underlined} \\ % you can also use a `\multicolumn{1}{c}{bold}` here, as you did.
12,345 & \uline{56,789} \\
1.53 & 45.1 \\
13.4 & .456 \\
\end{tabular}
\end{table}
\end{document}