0

page table coming from a csv file. My problem: there is an error arrising in the condition before the table. Do you know how I can fix this problem? (Not all the data is shown but it is important that the table stays multi-page like.

\documentclass[a4paper, 11pt]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\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}
%________________________________________________________________________
\newenvironment{conditions}
{\par\vspace{\abovedisplayskip}\noindent\tabularx{\textwidth}{>{$}l<{$} @{${}={}$} X}}
{\endtabularx\par\vspace{\belowdisplayskip}}
%________________________________________________________________________
% Part 4
\begin{filecontents*}{exp4.csv}
0.2,320.1
0.4,319.5
0.6,317.7
\end{filecontents*}
%________________________________________________________________________
\begin{document}
%________________________________________________________________________

\begin{conditions} 
\kappa & specific conductivity [$\si{\siemens~\cm^{-1}}$]  \\
 \end{conditions}

\begin{tabularx}{\textwidth}{|X|X|}
    \hline
    \bfseries V EDTA [\si{\milli\liter}] & \bfseries value 1 
    \csvreader[no head]{exp4.csv}{}{\\ \hline \csvcoli & \csvcolii }
    \\ \hline
\end{tabularx}

\end{document}
5
  • 1
    Currently you use ltablex to make tabularx tables be able to occupy multiple pages (This is not the standard behaviour of tabularx.) ltablex seems to cause the issue here. Would you mind switching to an alternative package such as xltabular instead?
    – leandriis
    May 22 '20 at 9:41
  • 1
    Is there a special reason for using tabularx for this kind of table in the first place? You introduce a huge amount of white space in the table making it less visually appealing and harder to read. Why not use two l type columns and a regular longtable instead?
    – leandriis
    May 22 '20 at 9:43
  • could you give me an example? that would be very helful :) the reason why i used tabularx was that I can split the chart on two pages because there are to many rows for having the table only on one page but if you have a better solution that would be great
    – Elia
    May 22 '20 at 9:50
  • 1
    The tabularx package does not allow you to make tables span multiple pages. It only allows you to use X type columns and specify an overall width for the table. If you want tables that can span multiple pages, use longtable. If you want to combine the features of tabularx(X type columns) and longtable(pagebreaks) in one table, there are multiple packages. One of them is ltablex that you used and that also causes the error message here. An alternative to that is the xltabular package that I used in my answer.
    – leandriis
    May 22 '20 at 9:59
  • 1
    Your table currently only contains two columns with wuite narrow contents in each. With your use of \begin{tabularx}{\textwidth} you made the actually quite narrow table as wide as the textwidth introducing a lot of unused white space in both columns. For such a table with few columns and narrow contents in each columns, there is no need for X type columns (and tabularxor xltabular at all). You can just use a regular longtable instead as I showed in my answer.
    – leandriis
    May 22 '20 at 10:02
1

Here are two examples using either xltabular or longtable:

enter image description here

\documentclass[a4paper, 11pt]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage[left=3cm,top=3cm,right=3cm]{geometry}
\usepackage{tabularx}
%\usepackage{ltablex} % removed to get rid of error message
%  \keepXColumns
\usepackage{xltabular} % added to be able to use xltabular environment. with this package, use tabularx if you don't want a pagebreak, use xltabular of you do want a pagebreak inside of a table.
\usepackage{xfrac}
\usepackage{float}
\newcolumntype{Y}{>{\small\raggedright\arraybackslash}X}
\usepackage{csvsimple}
%________________________________________________________________________
\newenvironment{conditions}
{\par\vspace{\abovedisplayskip}\noindent\tabularx{\textwidth}{>{$}l<{$} @{${}={}$} X}}
{\endtabularx\par\vspace{\belowdisplayskip}}
%________________________________________________________________________
% Part 4
\begin{filecontents*}{exp4.csv}
0.2,320.1
0.4,319.5
0.6,317.7
\end{filecontents*}
%________________________________________________________________________
\begin{document}
%________________________________________________________________________

\begin{conditions} 
\kappa & specific conductivity [$\si{\siemens~\cm^{-1}}$]  \\
\end{conditions}

xltabular version

\begin{xltabular}{\textwidth}{|X|X|}
    \hline
    \bfseries V EDTA [\si{\milli\liter}] & \bfseries value 1 
    \csvreader[no head]{exp4.csv}{}{\\ \hline \csvcoli & \csvcolii }
    \\ \hline
\end{xltabular}

longtable version

\begin{longtable}{|l|l|}
    \hline
    \bfseries V EDTA [\si{\milli\liter}] & \bfseries value 1 
    \csvreader[no head]{exp4.csv}{}{\\ \hline \csvcoli & \csvcolii }
    \\ \hline
\end{longtable}

\end{document}
3
  • Thank you very much for your explanation. That helps me a lot to understand how to use the different type of charts. I was not very familiar with this.
    – Elia
    May 22 '20 at 10:08
  • Could I also use \usepackage{multicol} with this in order two have 2 colums on just one page? (\begin{multicols}{2} and \end{multicols})
    – Elia
    May 22 '20 at 10:16
  • No, longtable does only work in onecolumn mode. However, here tex.stackexchange.com/a/230652/134144 is way to make it work nevertheless.
    – leandriis
    May 22 '20 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.