Graphics, Figures & TablesCSVReader[] with multicolumn

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
snorte
Posts: 3
Joined: Thu Feb 01, 2018 3:02 pm

CSVReader[] with multicolumn

Post by snorte »

I would like to create this table imported by csv file. My problem is to create some multicolumn in the table. Like this:
Table example
Table example
latex_tab.png (23.03 KiB) Viewed 5825 times

Code: Select all

\documentclass{article}
\usepackage{longtable}


\usepackage{csvsimple}

\usepackage[landscape,   margin=3cm,left=1cm]{geometry}%\usepackage{lscape} %pacote pagina horizontal
 %\usepackage{adjustbox}
 \usepackage{tabularx}
% \usepackage{longtable}
 \usepackage{array,longtable}

 %permite centrar os dados ao centro da tabela
 \newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
 \newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
%encoding
%--------------------------------------
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}


\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{graphicx}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\chead{\includegraphics[width=12cm]{logotipo_novo.png}}

\usepackage{color}

%--------------------------------------

%Portuguese-specific commands
%--------------------------------------
\usepackage[portuguese]{babel}
%--------------------------------------

%Hyphenation rules
%--------------------------------------
\usepackage{hyphenat}
\hyphenation{mate-mática recu-perar}
%--------------------------------------

\usepackage[table]{xcolor}
\usepackage{colortbl}


\begin{document}      
    \hspace{1cm}
    \begin{longtable}{|M{1.5cm}|M{2cm}|M{2cm}|M{2cm}|M{2cm}|M{2cm}|M{2.3cm}|M{2cm}|M{2cm}|M{1.5cm}|M{1.5cm}|}

    \caption*{Departamento de Matemática e Ciências Experimentais}\\\hline
     & Organização & Atividade & Responsáveis & Interveniente & Escola & Enquadramento & P.Educativo & Articulação & Custo & Aprovação\\\hline
    \endfirsthead
    %\multicolumn{3}{@{}l}{\ldots continued}\\\hline
    \hline
     & Organização & Atividade & Responsáveis & Interveniente & Escola & Enquadramento & P.Educativo & Articulação & Custo & Aprovação\\\hline
    \endhead % all the lines above this will be repeated on every page
    \hline
    %\multicolumn{3}{r@{}}{continued \ldots}\\
    \endfoot
    \hline
    \endlastfoot

    \hline
    \centering
    \csvreader[
    column count=11,
    %no head,
    table head=\hline,
       late after line=\\\hline 
    ]{mat.csv}{
      1=\one, 2=\two, 3=\three, 4=\four,
      5=\five, 6=\six, 7=\seven, 8=\eight,
      9=\nine, 10=\ten, 11=\eleven
    } 
     {\one & \two & \three & \four & \five & \six & \seven & \eight & \nine & \ten & \eleven}

    \end{longtable}

    \end{document}
Thank you very much for the help

Stéphane

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10328
Joined: Mon Mar 10, 2008 9:44 pm

CSVReader[] with multicolumn

Post by Stefan Kottwitz »

Hi Stéphane,

welcome to the forum!

Can you please also post the CSV file as .txt document, so we can test it with that table?

Stefan
LaTeX.org admin
snorte
Posts: 3
Joined: Thu Feb 01, 2018 3:02 pm

CSVReader[] with multicolumn

Post by snorte »

mat.csv
CSV
(4.84 KiB) Downloaded 346 times
Thanks,

Stéphane
User avatar
Stefan Kottwitz
Site Admin
Posts: 10328
Joined: Mon Mar 10, 2008 9:44 pm

CSVReader[] with multicolumn

Post by Stefan Kottwitz »

Hi Stéphane,

I tested but it seems to be challenging. I don't have much time as I'm traveling now. But I can recommend to use the pgfplotstable package (click the link to get the package page with the manual). See for example the section 2.3 Configuring Row Appearance: Styles.

But I really would not add such a lot of redundant information in every second row, it doesn't make reading easier and takes space.

Stefan
LaTeX.org admin
snorte
Posts: 3
Joined: Thu Feb 01, 2018 3:02 pm

CSVReader[] with multicolumn

Post by snorte »

Hi Stefan,

I know its not easy to make it. I will check the pgfplotstable. If somebody have others ideas or sugestions? The ideas its to read from a csv files information and to organize the date in a table with latex.

Thanks a lot
Post Reply