我想创建这个通过csv
文件导入的表。我的问题是在表中创建一些多行。像这样:
这是我的代码:
\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}
我怎样才能更改我的代码以使其出现multirow
在我的桌子上?
答案1
只需将其放入\multirow
您的\csvreader
命令列表中即可。
您没有提供文件示例csv
,所以我自己编了一个。我推测它实际上有 12 列(最后一列是要放在第二行多列中的文本)。
我用它example-image-a
来代替你的背景图像。
filecontents
包和环境仅用于创建我的mat.csv
。当然,您在实际文档中不需要它们,因为您已经有了文件。
\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}