我想要的是:从 csv 文件(exp1.csv)制作图表。
问题:
- 我没有获得图表中显示的所有数据
- 我的表格的标题不一致(参见 \hline)你能帮我解决这两个问题吗?
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[left=3cm,top=3cm,right=3cm]{geometry}
\usepackage{tabularx}
\usepackage{xfrac}
\usepackage{float}
\newcolumntype{Y}{>{\small\raggedright\arraybackslash}X}
\usepackage{csvsimple}
\begin{filecontents*}{exp1.csv}
Ultrapure,0.406,0.384,0.362
Deionized,2.78,2.769,2.603
\end{filecontents*}
\begin{document}
\subsection*{Characterisation of chemicals}
\begin{table}[ht]{
\scalebox{1}{
\begin{tabularx}{\textwidth}{|Y||Y|Y|}
\bfseries Water type & \bfseries value 1 & \bfseries value 2\\
\csvreader[head to column names]{exp1.csv}{}
{\\\hline\csvcoli&\csvcolii& \csvcoliii}\\
\hline
\end{tabularx}}}
\end{table}
\end{document}
答案1
- 您的
csv
文件有四列,因此我猜您的表格也需要四列。 - 您的
csv
没有表头,因此使用选项no head
。
\documentclass[a4paper, 11pt]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[left=3cm,top=3cm,right=3cm]{geometry}
\usepackage{tabularx}
\usepackage{xfrac}
\usepackage{float}
\newcolumntype{Y}{>{\small\raggedright\arraybackslash}X}
\usepackage{csvsimple}
\begin{filecontents*}{exp1.csv}
Ultrapure,0.406,0.384,0.362
Deionized,2.78,2.769,2.603
\end{filecontents*}
\begin{document}
\subsection*{Characterisation of chemicals}
\begin{table}[ht]
\begin{tabularx}{\textwidth}{*3{|Y}|Y|}
\hline
\bfseries Water type & \bfseries value 1 & \bfseries value 2 & \bfseries value 3
\csvreader[no head]{exp1.csv}{}{\\ \hline \csvcoli & \csvcolii & \csvcoliii & \csvcoliv}
\\ \hline
\end{tabularx}
\end{table}
\end{document}
后续:具有X
列类型的多页表
- 加载
ltablex
并使用激活列类型\keepXColumns
的效果。X
- 移动浮动环境
tabularx
的环境输出,并使用类似环境。例如,使用in来添加标题。table
tabularx
longtable
\caption{...} \\
tabularx
\documentclass[a4paper, 11pt]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[left=3cm,top=3cm,right=3cm]{geometry}
\usepackage{tabularx}
\usepackage{ltablex}
\keepXColumns
\usepackage{xfrac}
\usepackage{float}
\newcolumntype{Y}{>{\small\raggedright\arraybackslash}X}
\usepackage{csvsimple}
\begin{filecontents*}{exp1.csv}
Ultrapure,0.406,0.384,0.362
Deionized,2.78,2.769,2.603
\end{filecontents*}
\begin{document}
\subsection*{Characterisation of chemicals}
\begin{tabularx}{\textwidth}{XXXX}
\caption{text} \\
\hline
\bfseries Water type & \bfseries value 1 & \bfseries value 2 & \bfseries value 3
\csvreader[no head]{exp1.csv}{}{\\ \hline \csvcoli & \csvcolii & \csvcoliii & \csvcoliv}
\\ \hline
\end{tabularx}
\end{document}