7

I would like to know if there is a way to use an \hdashrule or \hdashline inside a \ctableas a \midrule? If possible, it will obey to the same rules as the \midrule command, like adjusting automatically to the table width and conserving the vertical spacing between the rows.

I tried the following table :

\documentclass[11pt]{book}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[francais]{babel}
\usepackage{multicol,bm}
\usepackage{array, booktabs}
\usepackage{ctable, dashrule}
\usepackage[left=2cm, right=2cm, top=2cm, bottom=2cm]{geometry}

\begin{document}
\ctable[caption= {Paramètres},
        label  = {tab:paramètres},
        ]
        {m{6.cm} m{3.5cm} l }
        {\tnote[$\ast$]{Dans le repère du solide.} \tnote[$\ast \ast$]{Autour de l'axe de rotation.}}{
        \toprule
            &   \textbf{Premier Solide} &   \textbf{Deuxième Solide}\\
        \midrule
        \textbf{Masse (kg)} &   4,4839  &   3,8177\\
        \multicolumn{3}{c}{\hdashrule{8cm}{1pt}{1pt 5pt}} \\
        \textbf{Centre de masse\tmark[$\ast$] ($\bm{x}\,;\, \bm{y}$) (m)}   &   (0 ; 0,1940)    & (0 ; 0,1613)\\
        \multicolumn{3}{c}{\hdashrule{8cm}{1pt}{1pt 5pt}} \\
        \textbf{Moment d'inertie\tmark[$\ast \ast$] (kg$\cdot$m\textsuperscript 2)}&    0,0913  &   0,0615\\
        \bottomrule}

\end{document}

Unfortunately, these dashed lines don't adjust automatically to the table width, and even worse, they do not conserve the vertical spacing between rows!

Is there a way to make this simple and automatic?

Note : I also tried replacing

\multicolumn{3}{c}{\hdashrule{8cm}{1pt}{1pt 5pt}}

by

\hdashline[1pt/3pt]

\hdashline has the advantage to automatically adjust to the table width, but it doesn't conserve the booktabs vertical spacing laws. Also, one can't control the size of the dashed line using this command.

0

1 Answer 1

6

enter image description here

new version keeping the rule within the table

\documentclass[10pt]{book}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[francais]{babel}
\usepackage{multicol,bm}
\usepackage{array, booktabs}
\usepackage{ctable, dashrule}

 \usepackage[left=2cm, right=2cm, top=2cm, bottom=2cm]{geometry}

\makeatletter

\def\xmidrule{%
\noalign{\vskip\aboverulesep}%
\multispan{3}{\leaders\hbox to 4pt{\hss\vrule\@height\cmidrulewidth\@width 2pt \relax\hss}\hfill\kern0pt}\cr%
\noalign{\vskip\belowrulesep}%
}
\makeatother

\begin{document}


\noindent X \dotfill X

\ctable[caption= {Paramètres},
        label  = {tab:paramètres},
        ]
        {m{6.cm} m{3.5cm} l }
        {\tnote[$\ast$]{Dans le repère du solide.} \tnote[$\ast \ast$]{Autour de l'axe de rotation.}}{
        \toprule
            &   \textbf{Premier Solide} &   \textbf{Deuxième Solide}\\
        \midrule
        \textbf{Masse (kg)} &   4,4839  &   3,8177\\
        \xmidrule
        \textbf{Centre de masse\tmark[$\ast$] ($\bm{x}\,;\, \bm{y}$) (m)}   &   (0 ; 0,1940)    & (0 ; 0,1613)\\
        \multicolumn{3}{c}{\hdashrule{8cm}{1pt}{1pt 5pt}} \\
        \textbf{Moment d'inertie\tmark[$\ast \ast$] (kg$\cdot$m\textsuperscript 2)}&    0,0913  &   0,0615\\
        \bottomrule}

\end{document}
6
  • Thanks for your help! The issue is that I tried your solution, and it extends to the full length of the document. What I mean is that when you modify the geometry and add the following line to the header : \usepackage[left=2cm, right=2cm, top=2cm, bottom=2cm]{geometry}, the line gets out of the table...
    – Meclassic
    Mar 3, 2013 at 14:07
  • @jrojasqu code updated Mar 3, 2013 at 14:50
  • I don't mean to be annoying... But how do you define the \xmidrule? I can't find it in your answer...
    – Meclassic
    Mar 3, 2013 at 16:58
  • oops:-)........ it was there in my file, obviously cut and paste is beyond my skills.... Mar 3, 2013 at 17:00
  • try now, sorry about that:-) Mar 3, 2013 at 17:05

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.