我的一个文档\setcapwidth
为了得到更窄的标题而忽略了我设置的参数。经过长时间的搜索,我发现当我注释掉该行时它开始起作用\setkomafont{caption}{\sffamily\footnotesize}
。
这是注释掉该行的输出:
我做错了什么吗?我该怎么做才能同时使用两者?
以下是最小工作示例:
\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{booktabs}
\setkomafont{caption}{\sffamily\footnotesize} % This is the line in question
\begin{document}
\begin{table}[tbp]
\footnotesize
\centering
\setcapwidth[c]{8cm}
\caption{This is a rather long caption for a table that is comparatively narrow --- but it's a test}
\label{table:setcapwidth_table}
\begin{tabular}{@{} l r r @{}}
\toprule
Row 1 & Row 2 & Row 3 \\
\midrule
2011& 10,000 & 10,000 \\
2012 & 10,000 & 10,000 \\
2013 & 10,000 & 10,000 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
编辑:我标记为“行”的显然是“列”......
答案1
添加选项:
[captions=nooneline]
解决了这个问题。
captions=
当我修改答案(添加了更多标题选项)时,我删除了,它再次停止工作。令人困惑。如果删除\footnotesize
,它也会按预期工作。这不是错误,正如@esdd在下面的评论中解释的那样。默认情况下captions=oneline
,\setcapwidth
仅影响超过的标题一线,IE:比文本宽度更宽。因此,当您像之前一样减小字体大小时,即使标题比您给出的值更宽,标题也会再次适合文本宽度,并成为一行标题\setcapwidth
。它不会被改变\setcapwidth
。很高兴知道!
除了[captions=nooneline]
,您还可以使用居中的、\minipage
您喜欢的宽度(此处为 8 厘米)的环境,并将表格置于该环境的中心:
示例 1 – 居中minipage
\documentclass[captions=nooneline, captions=tableabove]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{booktabs, relsize}
\setkomafont{caption}{\sffamily\footnotesize} % This is the line in question
\begin{document}
\begin{table}[tbp]
\centering
\footnotesize
\begin{minipage}{8cm}
\centering
\caption{This is a rather long caption for a table that is comparatively narrow --- but it's a test}
\label{table:setcapwidth_table}
\begin{tabular}{@{} l r r @{}}
\toprule
Row 1 & Row 2 & Row 3 \\
\midrule
2011& 10,000 & 10,000 \\
2012 & 10,000 & 10,000 \\
2013 & 10,000 & 10,000 \\
\bottomrule
\end{tabular}
\end{minipage}
\end{table}
\end{document}
示例 2 – threeparttable
另外,你可以将表格环境包含在三部分表如果您希望将标题的宽度与表格的宽度相匹配。作为额外的好处,您可以获得漂亮的集成表格注释。
\documentclass[captions=nooneline, captions=tableabove]{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{booktabs, threeparttable}
\setkomafont{caption}{\sffamily\footnotesize} % This is the line in question
\begin{document}
\begin{table}[tbp]
\footnotesize
\centering
\begin{threeparttable}
\caption{This is a rather long caption for a table that is comparatively narrow --- but it's a test}
\label{table:setcapwidth_table}
\begin{tabular}{@{} l r r @{}}
\toprule
Row 1 & Row 2 & Row 3 \\
\midrule
2011& 10,000 & 10,000 \\
2012 & 10,000 & 10,000 \\
2013 & 10,000 & 10,000 \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}