2

I am trying to create two tables: one with two columns and the other one with three columns, in both cases the first row should be one cell merged over all columns. Besides, the content of this first cell is spanning over more than one line. Here is my solution at the moment, but it works only for a fixed column number:

\documentclass{scrreprt}

\usepackage{booktabs} 

\usepackage{tabularx} 
\newcolumntype{b}{X} %type big
\newcolumntype{s}{>{\hsize=0.99\hsize}X} %type small. Above 1 does not make any difference
\newcommand{\heading}[1]{\multicolumn{2}{p{\textwidth}}{#1}} %For the cases where I am main author
%\newcommand{\heading}[1]{\multicolumn{3}{p{\textwidth}}{#1}} %For the cases where I am not main author

\usepackage[table,xcdraw]{xcolor}
\renewcommand{\arraystretch}{1.2} %(or 1.3). based on the advice in https://www.inf.ethz.ch/personal/markusp/teaching/guides/guide-tables.pdf

\usepackage{csquotes} 

\usepackage{siunitx} 
\sisetup{detect-all} 

\usepackage{pifont} 
\newcommand{\xmark}{\ding{55}} 

\begin{document}
This is my template for tables: documentation of authorship for the cumulative thesis.
\begin{table}[h!]
\centering
%\caption{My caption}
%\label{my-label}
\begin{tabularx}{\textwidth}{bs}
\toprule %requires the booktabs package.
%\multicolumn{2}{p{\textwidth}}{[ref] M. Name and L. Author, \enquote{Long title of a nice article reporting cool but complicated research}, \textit{Fancy journal} \textbf{2016}, \textit{13}, 001--007}  \\
\heading{[ref] M. Name and L. Author, \enquote{Long title of a nice article     reporting cool but complicated research} \textbf{2016}, \textit{13}, 001--007}\\
\midrule
Author                          & M. Name \\
\midrule %requires the booktabs package
Development of the concept      & \xmark   \\
\rowcolor[HTML]{C0C0C0} 
Preparation of the figures      & \xmark  \\ 
Preparation of the manuscript   & \xmark  \\ %\cmark \xmark require the pifont package and newcommand thing: http://tex.stackexchange.com/questions/42619/x-mark-to-match-checkmark 
\rowcolor[HTML]{C0C0C0} 
Correction of the manuscript    & \xmark   \\
\midrule 
Proposed publication equivalent & \num{1}  \\
\bottomrule     
\end{tabularx}
\end{table}

\end{document}

table with 2 columns

for the case with two columns and:

\documentclass{scrreprt}

\usepackage{booktabs} 

\usepackage{tabularx} 
\newcolumntype{b}{X} %type big
\newcolumntype{s}{>{\hsize=0.99\hsize}X} %type small. Above 1 does not make any difference
%\newcommand{\heading}[1]{\multicolumn{2}{p{\textwidth}}{#1}} %For the cases where I am main author
\newcommand{\heading}[1]{\multicolumn{3}{p{\textwidth}}{#1}} % For the cases where I am not main author

\usepackage[table,xcdraw]{xcolor}
\renewcommand{\arraystretch}{1.2} %(or 1.3). based on the advice in https://www.inf.ethz.ch/personal/markusp/teaching/guides/guide-tables.pdf

\usepackage{csquotes}

\usepackage{siunitx} %possible package for units
\sisetup{detect-all} 

\usepackage{pifont} 
\newcommand{\xmark}{\ding{55}} 

\begin{document}

This is my template for tables: documentation of authorship for the cumulative thesis.

\begin{table}[h!]
\centering
%\caption{My caption}
%\label{my-label}
\begin{tabularx}{\textwidth}{bss}
\toprule 
%\multicolumn{3}{p{\textwidth}}{[ref] F. Author, M. Name and L. Author,         \enquote{Long title of a nice article reporting cool but complicated research}, \textit{Fancy journal} \textbf{2016}, \textit{13}, 001--007}  \\
\heading{[ref] F. Author, M. Name and L. Author, \enquote{Long title of a nice article reporting cool but complicated research}, \textit{Fancy journal}     \textbf{2016}, \textit{13}, 001--007}\\
\midrule
Author                          & F. Author & M. Name \\
\midrule 
Development of the concept      & \xmark  & \\
\rowcolor[HTML]{C0C0C0} 
Programmation of the algorithm  & \xmark & \xmark  \\ 
Data acquisition                & \xmark &  \\
\rowcolor[HTML]{C0C0C0} 
Data analysis                   & \xmark & \xmark \\ 
Preparation of the manuscript   & \xmark & \\ %\cmark \xmark require the pifont package and newcommand thing: http://tex.stackexchange.com/questions/42619/x-mark-to-match-checkmark 
\rowcolor[HTML]{C0C0C0} 
Correction of the manuscript    & \xmark  & \xmark  \\
\midrule 
Proposed publication equivalent & \num{1} & \num{0,5} \\
\bottomrule     
\end{tabularx}
\end{table}

\end{document}

table with 3 columns

for the case with three columns.

Does anybody know how to programm this heading command so that it works for any column number?

Also, I have other minor aesthetic problems: the content of the table is spreading out on the right side, especially the grey lines are very obvious but also the title is too wide. Is there a way to fix this?

Does anybody understand why the point between first name and last name is visible in the heading but not in the first row (like M. Name and M Name)?

Finally I am not yet satisfied with the fixed cell width solution here, the columns end up too much on the right, maybe somebody has a suggestion how to make it prettier?

I would be super grateful for help, comments, suggestions!

3
  • 1
    Welcome! If you use variable widths for X-type columns, you must ensure that the total equals the number of X-type columns. But !+0.99 does not make 2 and 1+0.99+0.99 does not make 3. Also, you need to avoid using \multicolumn to span such columns. See the manual for tabularx for details.
    – cfr
    Jun 8, 2016 at 15:48
  • Do you really want to increase \arraystretch in addition to using booktabs's rules?
    – cfr
    Jun 8, 2016 at 15:49
  • 2
    p{\textwidth} is too wide. p{\dimexpr\textwidth-2\tabcolsep} works better. Jun 8, 2016 at 16:01

1 Answer 1

1

I'm not sure what caused the periods to disappear, as I am not that familiar will all the packages being used. Whatever the cause, using c instead of s fixed it.

\documentclass{scrreprt}

\usepackage{booktabs} 

\usepackage{tabularx} 
\newcolumntype{b}{X} %type big
%\newcolumntype{s}{>{\hsize=0.99\hsize}X} %type small. Above 1 does not make any difference
%\newcommand{\heading}[1]{\multicolumn{2}{p{\textwidth}}{#1}} %For the cases where I am main author
\newcommand{\heading}[1]{\multicolumn{3}{p{\dimexpr\textwidth-2\tabcolsep}}{#1}} % For the cases where I am not main author

\usepackage[table,xcdraw]{xcolor}
\renewcommand{\arraystretch}{1.2} %(or 1.3). based on the advice in https://www.inf.ethz.ch/personal/markusp/teaching/guides/guide-tables.pdf

\usepackage{csquotes}

\usepackage{siunitx} %possible package for units
\sisetup{detect-all} 

\usepackage{pifont} 
\newcommand{\xmark}{\ding{55}} 

\begin{document}

This is my template for tables: documentation of authorship for the cumulative thesis.

\begin{table}[h!]
\centering
%\caption{My caption}
%\label{my-label}
\begin{tabularx}{\textwidth}{bcc}
\toprule 
%\multicolumn{3}{p{\textwidth}}{[ref] F. Author, M. Name and L. Author,         \enquote{Long title of a nice article reporting cool but complicated research}, \textit{Fancy journal} \textbf{2016}, \textit{13}, 001--007}  \\
\heading{[ref] F. Author, M. Name and L. Author, \enquote{Long title of a nice article reporting cool but complicated research}, \textit{Fancy journal}     \textbf{2016}, \textit{13}, 001--007}\\
\midrule
Author                          & F. Author & M. Name \\
\midrule 
Development of the concept      & \xmark  & \\
\rowcolor[HTML]{C0C0C0} 
Programmation of the algorithm  & \xmark & \xmark  \\ 
Data acquisition                & \xmark &  \\
\rowcolor[HTML]{C0C0C0} 
Data analysis                   & \xmark & \xmark \\ 
Preparation of the manuscript   & \xmark & \\ %\cmark \xmark require the pifont package and newcommand thing: http://tex.stackexchange.com/questions/42619/x-mark-to-match-checkmark 
\rowcolor[HTML]{C0C0C0} 
Correction of the manuscript    & \xmark  & \xmark  \\
\midrule 
Proposed publication equivalent & \num{1} & \num{0,5} \\
\bottomrule     
\end{tabularx}
\end{table}

\end{document}

demo

You must log in to answer this question.

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