3

I currently have the following table: enter image description here

Which corresponds to the following code:

  \documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[font=small,labelfont=bf]{caption}

\usepackage[a4paper,top=2.5cm,bottom=2.5cm,left=2.5cm,right=2.5cm,marginparwidth=1.5cm]{geometry}
\linespread{1.5}
\usepackage{booktabs}
\usepackage{threeparttable}
\usepackage{tabularx}
\usepackage{adjustbox}
\usepackage[flushleft]{threeparttable}

\begin{document}
\begin{table}[h!]
\ra{0.8}
\centering
\caption{bla }
\begin{tablenotes}
\renewcommand\baselinestretch{1}
\small
    \item Note: bla.   
\end{tablenotes}
\setlength{\tabcolsep}{8pt}
\begin{tabular}{l | c | c c c c }
\toprule
  \multicolumn{1}{c}{\bfseries Panel A: Countries}\\
   \hline
 & Average & Netherlands &  Germany & France & Belgium  \\ \hline
Netherlands & 3.83 &  &  &  &    \\
Germany  & 3.87 &  &  &  &    \\
France  & 3.95 &  &  &  &    \\
Belgium  & 3.91 &  &  &  &    \\
\midrule
 \multicolumn{1}{c}{\bfseries Panel B: Clients}\\
   \hline
 & Average & Advisory &  Execution Only &  &   \\\hline
Advisory & 3.86 &  &  &  &    \\
Execution Only & 3.78 &  &    &  &  \\
\bottomrule
\end{tabular}\label{tab:VarImportc}

\end{table} 
\end{document}

I would like to include two diagonal dashed lines on the right hand sides of both panels (i.e. from Netherlands-Netherlands to Belgium-Belgium and Advisory-Advisory to Exec-Exec).

Also, I was wondering how I can make the first column (Average) distinct from the RHS of the table? I now did it via vertical lines, but it doesn't look very nice.

3

At first, your code had some minor errors. Secondly, your questions are not clear to me! BTW, as far as I noticed from your text, I will do it with the aid of tikz package. see the following code:

  \documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[font=small,labelfont=bf]{caption}

\usepackage[a4paper,top=2.5cm,bottom=2.5cm,left=2.5cm,right=2.5cm,marginparwidth=1.5cm]{geometry}
\linespread{1.5}
\usepackage{booktabs}
%\usepackage{threeparttable}
\usepackage{tabularx}
\usepackage{adjustbox}
\usepackage{tikz}
\usepackage[flushleft]{threeparttable}


\newcommand{\tikzmark}[1]{\noindent\tikz[overlay,remember picture] \node (#1) {};}

\begin{document}
\begin{table}[h!]
%\ra{0.8}
\centering
\caption{bla }
\begin{tablenotes}
\renewcommand\baselinestretch{1}
\small
    \item Note: bla.   
\end{tablenotes}
\setlength{\tabcolsep}{8pt}
\begin{tabular}{l || c || c c c c }
\toprule
  \multicolumn{1}{c}{\bfseries Panel A: Countries}\\
   \hline
 & Average & Netherlands &  Germany & France & Belgium  \\ \hline
Netherlands & 3.83 & \tikzmark{start}\phantom{Netherlands} &  &  &    \\
Germany  & 3.87 &  &  &  &    \\
France  & 3.95 &  &  &  &    \\
Belgium  & 3.91 &  &  &  &  \phantom{Belgium}\tikzmark{end}   \\
\midrule
 \multicolumn{1}{c}{\bfseries Panel B: Clients}\\
   \hline
 & Average & Advisory &  Execution Only &  &   \\\hline
Advisory & 3.86 &  &  &  &    \\
Execution Only & 3.78 &  &    &  &  \\
\bottomrule
\end{tabular}\label{tab:VarImportc}
\begin{tikzpicture}[overlay,remember picture]
    \draw [dashed] (start.north) -- (end.south);
\end{tikzpicture}
\end{table} 
\end{document}

enter image description here

  • Thanks. Perhaps a dumb question: when I try to do the same for the lower panel, the diagonal line for panel A disappears. I added \tikzmark{start}\phantom{Advisory} and \phantom{Execution Only}\tikzmark{end}. Am I doing something wrong? – Rik Jan 29 at 10:09
  • You will need to give the coordinates different names, e.g. \tikzmark{start2}\phantom{Advisory} and \tikzmark{end2}\phantom{Execution Only}, and then draw another dashed line further down, \draw[dashed] (start2.north) -- (end2.south); – rbrignall Jan 29 at 10:12
3

You can achieve this by placing a tikz coordinate in the relevant cells, using remember picture and overlay to then let you go back and draw lines after creating the table. For example (I've cut down your example to a MWE -- note that you are currently calling the threeparttable package twice, which you'll want to fix):

\documentclass{standalone}

\linespread{1.5}
\usepackage{booktabs}
\usepackage{threeparttable}
\usepackage{tabularx}
\usepackage{adjustbox}

\usepackage{tikz}
\begin{document}

\setlength{\tabcolsep}{8pt}
\begin{tabular}{l | c | c c c c }
\toprule
  \multicolumn{1}{c}{\bfseries Panel A: Countries}\\
   \hline
 & Average & Netherlands &  Germany & France & Belgium  \\ \hline
Netherlands & 3.83 & \tikz[remember picture,overlay]{\coordinate(Netherlands);} &  &  &    \\
Germany  & 3.87 &  &  &  &    \\
France  & 3.95 &  &  &  &    \\
Belgium  & 3.91 &  &  &  &  \tikz[remember picture,overlay]{\coordinate(Belgium);}  \\
\midrule
 \multicolumn{1}{c}{\bfseries Panel B: Clients}\\
   \hline
 & Average & Advisory &  Execution Only &  &   \\\hline
Advisory & 3.86 & \tikz[remember picture,overlay]{\coordinate(Advisory);} &  &  &    \\
Execution Only & 3.78 &  &  \tikz[remember picture,overlay]{\coordinate(Exec);}  &  &  \\
\bottomrule
\end{tabular}

\begin{tikzpicture}[remember picture,overlay]
\draw[dashed](Netherlands) -- (Belgium);
\draw[dashed](Advisory) -- (Exec);
\end{tikzpicture}

\end{document}

This draws a dashed line from teh centre of the corresponding cells. You can move the start/finish points by specifying an xshift and/or yshift parameter in the \coordinate commands, for example:

\tikz[remember picture,overlay]{\coordinate[xshift=20pt](Netherlands);}

This answer is based on similar work done here: Add TikZ node at corner of a tabular cell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.