1

I'm trying to set up a table in overleaf right now, but am struggling with the set up of the table and the visual results.

I'm used to setting up tables using hlines to add difference between the rows, however somehow it doesn't seem to work out as well when using the \multirow command. I've never encountered this issue before but somehow it runs the h line through the multi row without taking it into account. I found a solution by implementing clines instead of hlines but am not fully satisfied with the result, since the column borders at the topline are thicker than the ones below it.

Any suggestions as to how to achieve the same table set up, but more elegantly?

Thanks!

\documentclass{article}{two sided}
\usepackage[version=4]{mhchem}
\usepackage{rotating}
\usepackage[table,xcdraw]{xcolor}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{diagbox}
\usepackage[acronym,nonumberlist]{glossaries}
\renewcommand*{\glstextformat}[1]{\textcolor{black}{#1}}



\usepackage[scientific-notation = fixed, fixed-exponent = 0,per-mode=symbol]{siunitx}
\sisetup{detect-all}
\usepackage{wrapfig}
\usepackage{longtable}
\usepackage{float}
\usepackage{pdfpages}
\usepackage{rotating}

\usepackage{amsmath}
\usepackage{siunitx}

\begin{document}


\begin{table}[H]
\centering
\caption{Flux (\emph{J}) }
\label{tab:4.4.1}
\begin{tabular}{|l|l|l|l|l|l|l|ll}
\multirow{2}{*}{\begin{tabular}[l]{@{}l@{}} \textbf{energy}\\ \textbf{density (cm\textsuperscript{2}/MW)}\end{tabular}} &
\multicolumn{2}{|l|}{ \begin{tabular}[l]{@{}l@{}} \textbf{1064  }\end{tabular}} & 
         \multicolumn{2}{|l|}{ \begin{tabular}[l]{@{}l@{}} \textbf{532 } \end{tabular}}
  & \multicolumn{2}{|l|}{\begin{tabular}[l]{@{}l@{}} \textbf{355 }\end{tabular}} \\ \hline
 
  & \textbf{Volume ($\mu$L)}         &  \textbf{\emph{J} ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})}              & \textbf{Volume ($\mu$L)} &\textbf{\emph{J} ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})} &\textbf{Volume ($\mu$L)} & \textbf{\emph{J} ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})} \\ \hline

        10  &     $\pm$       &      $\pm$         & $\pm$ & & &  \\
        25 &      $\pm$         & $\pm$  &          $\pm$  & & &  \\
        50 &        $\pm$      & $\pm$    &    $\pm$      & & &    \\
        70 &        $\pm$      &  $\pm$   &    $\pm$      & & &    \\
        100 &       $\pm$       &  $\pm$   &     $\pm$    & & &     \\
\end{tabular}
\end{table}

\begin{table}[H]
\centering
\caption{flux (\emph{J}) }
\label{tab:4.4.2}
\begin{tabular}{|l|l|l|l|l|l|l|ll}
\multirow{2}{*}{\begin{tabular}[l]{@{}l@{}} \textbf{energy}\\ \textbf{density (cm\textsuperscript{2}/MW)}\end{tabular}} &
\multicolumn{2}{|l|}{ \begin{tabular}[l]{@{}l@{}} \textbf{1064 }\end{tabular}} & 
         \multicolumn{2}{|l|}{ \begin{tabular}[l]{@{}l@{}} \textbf{532 } \end{tabular}}
  & \multicolumn{2}{|l|}{\begin{tabular}[l]{@{}l@{}} \textbf{355 }\end{tabular}} \\ \cline{2-7}
 
  & \textbf{Volume ($\mu$L)}         &  \textbf{\emph{J} ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})}              & \textbf{Volume ($\mu$L)} &\textbf{\emph{J} ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})} &\textbf{Volume ($\mu$L)} & \textbf{\emph{J} ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})} \\ \hline

        10  &     $\pm$       &      $\pm$         & $\pm$ & & &  \\
        25 &      $\pm$         & $\pm$  &          $\pm$  & & &  \\
        50 &        $\pm$      & $\pm$    &    $\pm$      & & &    \\
        70 &        $\pm$      &  $\pm$   &    $\pm$      & & &    \\
        100 &       $\pm$       &  $\pm$   &     $\pm$    & & &     \\
\end{tabular}
\end{table}

\end{document}
6
  • Welcome. Do you have a draft of the final table?
    – Excelsior
    Mar 25, 2021 at 10:02
  • Probably you looking for \cline{<column x> - <column y>}. For further help please be so kind and extend your code fragments to one, small but complete document beginning with \documentclass{...} and ending with \end{document}, which reproduce your problem.
    – Zarko
    Mar 25, 2021 at 10:23
  • @Vincent -- probably something on the lines of the answer below -- I have not added the table environ -- makecell package is used to divide the headers in two parts upper and lower -- for symmetry the units have been kept below -- verticals have been removed you can add if u want
    – js bibra
    Mar 25, 2021 at 10:25
  • The double vertical lines are caused by you using \multicolumn{2}{|l|}. The last | combines with the first | in the next \multicolumn giving a double |. So make it \multicolumn{2}{|l}. And there is no need for the single-row tabulars, just put the text itself. Like \multicolumn{2}{|l}{\textbf{1064}} Mar 25, 2021 at 10:39
  • @PietervanOostrum Thanks for the comment, helped making it look a little smoother already!
    – Vincent
    Mar 29, 2021 at 9:39

3 Answers 3

1

As (off-topic) suplement to @js bibra nice answer (+1):

  • for units is used siunitx package
  • for table is used tabular* table environment with automatic calculation of the \tabcolsep distances
  • for multi column cells are defined by \NewExpandableDocumentCommand shortens \mcc
  • removed all clutter from table (nested tabulars)
\documentclass{article}
\usepackage{booktabs,  makecell, multirow}
\renewcommand\theadfont{\bfseries\normalsize}
\NewExpandableDocumentCommand\mcc{O{1}m}{\multicolumn{#1}{c}{#2}}
\usepackage{siunitx}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{table}[ht]
\caption{Flux ($J$) }
\label{tab:4.4.1}
%    \sisetup{per-mode = symbol}
\small
    \setlength\tabcolsep{0pt}
    \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} 
                        S[table-format=3.0]
               *{6}{>{$}c<{$}}   
                    }
    \toprule
{\multirow{3}{*}{\thead{energy\\ density\\
                         (\si{\centi\metre\squared\per\mega\watt})}}}
    &   \mcc[2]{\thead{1064}}
        &   \mcc[2]{\thead{532}}
            &   \mcc[2]{\thead{355}}   \\ 
    \cmidrule(r){2-3}\cmidrule(r){4-5}\cmidrule{6-7}
    &   $\thead{Volume\\ (\si{\micro\litre})}$
        &   $\thead{$J$\\ (\si{\per\micro\liter\per\hour})}$
            &   $\thead{Volume\\ (\si{\micro\liter})}$
                &   $\thead{$J$\\ (\si{\per\micro\liter\per\hour})}$
                     &  $\thead{Volume\\ (\si{\micro\liter})}$
                        &   $\thead{$J$\\ (\si{\per\micro\liter\per\hour})}$ \\
    \midrule

10  & \pm   & \pm   & \pm   &   &   &   \\
25  & \pm   & \pm   & \pm   &   &   &   \\
50  & \pm   & \pm   & \pm   &   &   &   \\
70  & \pm   & \pm   & \pm   &   &   &   \\
100 & \pm   & \pm   & \pm   &   &   &   \\
    \bottomrule
\end{tabular*}
    \end{table}
\end{document}

enter image description here

(red lines indicate text border)

1
  • Thanks looks great, how would it be possible for me to still add the vertical lines in the bottom part?
    – Vincent
    Mar 29, 2021 at 9:53
1

enter image description here

\documentclass{article}

\usepackage{ multirow,makecell, booktabs}
%
\begin{document}

\begin{table}

    \caption{Flux (\emph{J}) }
    \label{tab:4.4.1}
    \noindent\hspace{-2cm}
    \begin{tabular}{*9{c}}\toprule
        &\multicolumn{2}{c}{ \begin{tabular}[l]{@{}l@{}} \textbf{1064 }\end{tabular}} 
        &\multicolumn{2}{c}{ \begin{tabular}[l]{@{}l@{}} \textbf{532 } \end{tabular}}
        &\multicolumn{2}{c}{\begin{tabular}[l]{@{}l@{}} \textbf{355 }\end{tabular}} \\ \cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}
        
        \multicolumn{1}{c}{\makecell[c]{\textbf{energy density} \\\textbf{(cm\textsuperscript{2}/MW)}}}    
        & \makecell[c]{\textbf{Volume}\\ \textbf{($\mu$L)}}
        & \makecell[c]{\textbf{\emph{J}}\\ \textbf{ ($\mu$L\textsuperscript{-1} h\textsuperscript{-1})}}
        &\makecell[c]{\textbf{Volume} \\\textbf{($\mu$L)}}&\makecell[c]{\textbf{\emph{J}} \\\textbf{($\mu$L\textsuperscript{-1} h\textsuperscript{-1})}} &\makecell[c]{\textbf{Volume}\\\textbf{ ($\mu$L)}}& \makecell[c]{\textbf{\emph{J}} \\\textbf{($\mu$L\textsuperscript{-1} h\textsuperscript{-1})}} \\ \midrule
        
        10  & $\pm$ & $\pm$  & $\pm$ & & &  \\
        25  & $\pm$ & $\pm$  & $\pm$ & & &  \\
        50  & $\pm$ & $\pm$  & $\pm$ & & &  \\
        70  & $\pm$ &  $\pm$ & $\pm$ & & &  \\
        100 & $\pm$ &  $\pm$ & $\pm$ & & &  \\ \bottomrule
    \end{tabular}
    \end{table}

\end{document}
1
  • Thank you soo much for the answer, it looks a lot better than the solution I implemented so far!
    – Vincent
    Mar 29, 2021 at 9:27
0

You can also just use multicolumn to get it done.

\documentclass{article}

\usepackage{float}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
    \begin{table}[H]
        \centering
        \caption{Flux (\emph{J}) }
        \label{tab:4.4.1}
        \begin{tabular}{@{}ccccccc@{}}
            \toprule
             & \multicolumn{2}{c}{\textbf{1064}} & \multicolumn{2}{c}{\textbf{532}} & \multicolumn{2}{c}{\textbf{355}} \\ \midrule
            $\boldsymbol{\rho}$ & $\boldsymbol{V}$ & $\boldsymbol{J}$ & $\boldsymbol{V}$ & $\boldsymbol{J}$ & $\boldsymbol{V}$ & $\boldsymbol{J}$ \\ 
            $\boldsymbol{(cm^2 {MW}^{-1})}$ & $\boldsymbol{(\mu L)}$ & $\boldsymbol{({\mu L}^{-1} h^{-1})}$ & $\boldsymbol{(\mu L)}$ & $\boldsymbol{({\mu L}^{-1} h^{-1})}$ & $\boldsymbol{(\mu L)}$ & $\boldsymbol{({\mu L}^{-1} h^{-1})}$ \\ \midrule
            10 & $\pm$ & $\pm$ & $\pm$ & & & \\
            25 & $\pm$ & $\pm$ & $\pm$ & & & \\
            50 & $\pm$ & $\pm$ & $\pm$ & & & \\
            70 & $\pm$ & $\pm$ & $\pm$ & & & \\
            100 & $\pm$ & $\pm$ & $\pm$ & & & \\ \midrule
            \multicolumn{7}{l}{$\boldsymbol{\rho}$ ... energy density; $\boldsymbol{V}$ ... volume; $\boldsymbol{J}$ ... flux} \\ \bottomrule
        \end{tabular}
    \end{table}

enter image description here

1
  • Thanks a lot Excelsior!
    – Vincent
    Mar 29, 2021 at 9:28

You must log in to answer this question.

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