0

I am working on the auto-creation of a report after running a parametric study. In order to summarize all the results, I put the the important data as well as the case name in a table. For convenience purposes, the name of the case is associated to an hyperref link which leads to the section of the document where the case is studied. To create this table, I used the package csvautotabular. The links are working, but the the table is too long (more than 4 pages). So I switch to csvautolongtable (with the addition of the lontable package). Then the links are not working. I have no clue about this issue.

How can I create a long table with hyperref inside the table from a csv file (the csv file is important, and it is created with a python script) ?

Here is the working minimal example with hypperef:

\documentclass[a4paper, 11pt, twoside,openright]{article}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage{fancyhdr}        
\usepackage{csvsimple}
\usepackage{longtable}
\usepackage{hyperref}
\usepackage{adjustbox}
\usepackage{grffile}    

\begin{document}
\newpage
    \section{Results summary}
    test
        \begin{table}
               \begin{adjustbox}{width=\columnwidth,center}
                \csvautotabular{Summary-MWE.csv}
               \end{adjustbox}
        \end{table}
        \section{test1}
        \label{test1}
        blabla
        \section{test2}
        \label{test2}
        blablablabla
        
\end{document}

Here the minimal example with autolongtable (I have to delete the adjustbox environment to make it works):

\documentclass[a4paper, 11pt, twoside,openright]{article}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage{fancyhdr}    
\usepackage{csvsimple}
\usepackage{longtable}
\usepackage{hyperref}
\usepackage{adjustbox}
\usepackage{grffile}    

\begin{document}
\newpage
    \section{Results summary}
    blabbla test
        % \begin{table}
               % \begin{adjustbox}{width=\columnwidth,center}
                \csvautolongtable[respect all]{Summary-MWE.csv}
               % \end{adjustbox}
        % \end{table}
        \section{test1}
        \label{test1}
        blabka
        \section{test2}
        \label{test2}
        blablablabla
        
\end{document}

Here is a copy of the csv file (on one column):

Case,Value1,Value2,Value3,Value4
c \hyperref[test1]{Geom1},7920.0,0.452,0.776,1.7
c \hyperref[test2]{Geom2},990.0,0.452,0.78,0.2
2
  • 1
    Welcome to TEX.SE! Please provide a full minimal working example which reproduces the issue, starting with \documentclass{...} and ending with \end{document} – gman Jul 15 '20 at 9:20
  • Thank you, I add the minimal working example. – Kola Jul 15 '20 at 12:41
0

Here a version using the datatool package instead of csvsimple. Could you plz. check if this works for you as expected?

\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{hyperref}

\usepackage{datatool}
\DTLsetseparator{,}
\DTLloaddb{data}{Summary-MWE.csv}
    
\begin{document}
\newpage
    \section{Results summary}
    blabbla test
    
        \begin{table}
        \begin{longtable}{lcccc}
            \toprule
            \DTLforeach*{data}
            {\case=Case, \va=Value1, \vb=Value2, \vc=Value3, \vd=Value4}
            {\case & \va & \vb & \vc & \vd \\}%
            \\[-15pt]\bottomrule
        \end{longtable}    
        \end{table}
        \section{test1}
        \label{test1}
        blabka
        \section{test2}
        \label{test2}
        blablablabla
\end{document}

Edit: An even more simple solution without all the CSV reading would be to change your data file slightly and import it directly into your LaTeX file.

\documentclass{article}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{hyperref}

\begin{document}
\newpage
    \section{Results summary}
    blabbla test
    
        \begin{longtable}{lcccc}
            \toprule
            \input{Summary-MWE.csv}
            \bottomrule
        \end{longtable}    
        \section{test1}
        \label{test1}
        blabka
        \section{test2}
        \label{test2}
        blablablabla
\end{document}

and for your data file you just remove the header line and replace the comma by and and-symbol and put a double backslash \\ at the end of each line like this:

c \hyperref[test1]{Geom1}&7920.0&0.452&0.776&1.7\\
c \hyperref[test2]{Geom2}&990.0&0.452&0.78&0.2\\
...

Unfortunately, this solution also does not work within the table environment.

2
  • Ok, the links are working, but for very long table, it didn't go on the following pages. But if I delete the \begin{table} \end{table}, it works. Thank you for your help! – Kola Jul 16 '20 at 8:38
  • Having control of each table entry also allows you to put your LaTeX code you currently have within your data file (\hyperref[test1]{Geom1}) into the LaTeX file where it belongs to, e.g., like this: {\case \hyperref[test\DTLcurrentindex]{Geom\DTLcurrentindex} & \va & \vb & \vc & \vd \\}, where \DTLcurrentindex will give you the current row-index. – susis strolch Jul 16 '20 at 18:16

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.