3

I would like to create this table imported by csv file. My problem is to create some multirows in the table. Like this:

enter image description here

This is my code:

\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}

How can I change on my code to make the multirow on my table?

3
  • Welcome to TeX.SX! Could you please add the necessary packages to compile the example?
    – egreg
    Jan 31, 2018 at 13:54
  • \documentclass{article} \usepackage{csvsimple} \usepackage[landscape, margin=3cm,left=1cm]{geometry}%\usepackage{lscape} %pacote pagina horizontal \usepackage{tabularx} \usepackage{array,longtable} \newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}} \newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{fancyhdr} \pagestyle{fancy} \usepackage{graphicx} \renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt} \usepackage[portuguese]{babel} Jan 31, 2018 at 14:41
  • Please edit the information in your question, instead.
    – egreg
    Jan 31, 2018 at 14:59

1 Answer 1

2

Just put your \multirow in your \csvreader command list.

You didn't provide an example of your csv file, so I have invented it. I presume it actually has 12 columns (with the last one being the text to be put in the multicolumn of the second row).

I used example-image-a instead of your background image.

filecontents package and environment are only used to create my mat.csv. Of course, you do not need them in your actual document, since you already have your file.

\documentclass{article}
\usepackage[landscape,   margin=3cm,left=1cm]{geometry}%\usepackage{lscape} %pacote pagina horizontal
%encoding
%--------------------------------------
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%Portuguese-specific commands
%--------------------------------------
\usepackage[portuguese]{babel}
%--------------------------------------

\usepackage{longtable}
\usepackage{multirow}
\usepackage{csvsimple}
 %\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}}


\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{graphicx}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\chead{\includegraphics[width=12cm]{example-image-a}}

%\usepackage{color} xcolor loaded afterwards

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

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

\usepackage{filecontents}
\begin{filecontents*}{mat.csv}
1,2,3,4,5,6,7,8,9,10,11,multicolumn
a,b,c,d,e,f,g,h,i,j,k, something
l,m,n,o,p,q,r,s,t,u,v, something else
w,x,y,z,0,1,2,4,5,6,7, and something else again
I,have,invented,this,file,because,you,do,not,provide,an, example of your csv
I,presume,it,actually,has,12,{colums,},not,only,{11,},and, that the last one is a description
\end{filecontents*}

\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, 12=\mydescr
    } 
     {\multirow{2}{*}{\one} & \two & \three & \four & \five & \six & \seven & \eight & \nine & \ten & \eleven\\\cline{2-11} & \multicolumn{10}{l|}{\mydescr}}
    \end{longtable}

    \end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .