我有一张由 pgfplotstable 生成的表格。我想强制将两个标题换行到两行,但我无法让它工作。
这是我的脚本:
\documentclass{article}
% Set the values for the biblography
\usepackage[
isbn=false,
url=false,
doi=false,
eprint=false,
]{biblatex}
% For tables
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{array}
\usepackage{caption}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\pgfplotstableset{
font={\small},
empty cells with={--}, % replace empty cells with ’--’
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule}
}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
%Set column width (This is my fix...)
\setlength{\tabcolsep}{3.5pt}
% Create command for paragraph style (new line after)
\newcommand{\myparagraph}[1]{\paragraph{#1}\mbox{}\\}
\begin{document}
\myparagraph{paragraph}
Blalalala
% Add table
\begin{table}
\caption{My table}
\centering
\pgfplotstabletypeset[
columns/City/.style={string type},
columns/Wrap it/.style={column type=|C},
col sep=comma]{table.csv},
\end{table}
\end{document}
Paragraph ended before \NC@find was complete.
我在该行之前收到了错误\end{table}
。
这是我的 table.csv
City,Wrap it
London,12
Paris,12
Rome,323
我希望标题“换行”分为两行,这样只减少第二列的宽度。
答案1
您需要从列声明中删除参数或使用C{2.5em}
。然后您的示例就可以正常工作。
\documentclass{article}
\usepackage{pgfplotstable,booktabs,array}
\newcolumntype{C}{>{\centering\arraybackslash}m{2.5em}}
\pgfplotstableset{
font={\small},
empty cells with={--}, % replace empty cells with ’--’
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule}
}
\begin{document}
\begin{table}
\caption{My table}
\centering
\pgfplotstabletypeset[
columns/City/.style={string type},
columns/Wrap it/.style={column type=|C},
col sep=comma]{
City,Wrap it
London,12
Paris,12
Rome,323
},
\end{table}
\end{document}