# How to create a dashed line in tabularx environment

I've been looking into this, and I have encountered two main "solutions":

\usepackage{arydshln}


As decribed here.

And this one:

\usepackage{dashrule}


As described in this other post.

\usepackage{array}
\usepaclage{tabularx}
\usepackage{longtable}
\usepackage{tabu}


It seems I can't use neither arydshln nor dashline.

Any idea why this is happening? How can I get a dashed horizontal line inside my tabularx which is at the same time- inside a table environment?

This is what I have:

\documentclass{article}

\usepackage{multirow}
\usepackage{array}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{tabu}

\begin{document}
Hello.

\begin{longtabu}{l p{0.8\linewidth}}
WHO                 &   \hspace{5mm} World Health Organization\\[1mm]
GDP                 & \hspace{5mm} Gross Domestic Product\\[1mm]
PPP                 & \hspace{5mm} Purchasing Power Parities\\[1mm]

\end{longtabu}

\begin{table}\tiny
\caption{Muscles of the thigh}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\begin{tabularx}{\textwidth}{YYYYY}
Muscle & Origin & Insertion& Nerve & Action \\
\firsthline\\
\textbf{Anterior Compartment}   & & &   &   \\[3mm]

Rectus Femoris: anterior inferior iliac spine. Vastus Lateralis: greater trochanter and linea aspera of femur. Vastus Intermedius: body of femur.  Vastus Medialis: linea aspera of femur                &
Patella and onto tibial tuberosity through patellar ligament        &
Femoral                                                                                                                 &
Extends knee; rectus femoris also flexes hip\\\\

Sartorius                                                                                                               &
Anterior superiro iliac spine                                                                       &
Medial side of tibial tuberosity                                                                &
Femoral                                                                                                                 &
Flexes hip and knee; rotates thigh laterally and leg medially\\\\

\hline\\% I want this line to be dashed
\textbf{Medial Compartment} & & &   &   \\[3mm]

Pubis                                                                                                                       &
Pectineal line and linea aspera of femur                                                &
Obturator                                                                                                               &
Adducts, laterally rotates thigh; flexes hip\\\\

Pubis                                                                                                                       &
Linea aspera of femur                                                                                       &
Obturator                                                                                                               &
Adducts, laterally rotates thigh; flexes hip\\\\

\lasthline\\
\end{tabularx}
\label{tab:ThighMuscles2}
\end{table}

\end{document}


Now, if I use \dashrule where the \hline is (after loading the dashrule package, of course), I get an Undefined control sequence error.

If I use the \hdashline (of the arydshln package) I get 101 errors which point me to other tables in my document, so I'm guessing it has something to do with incompatibility with the other packages I loaded.

• Please post a complete small document that shows the problem. – David Carlisle Apr 2 '13 at 10:28
• Please, an example should always start with \documentclass and end with \end{document} so that other people can run it, and shows which packages you have loaded. – David Carlisle Apr 2 '13 at 10:50
• I'm not sure how to do this, since I created my own style for my thesis... so I'm loading a lot of packages. Should I include only the "relevant" information? – Mario S. E. Apr 2 '13 at 10:52
• See this answer But basically anyone trying to help you is going to need a document using article class that includes that table and that uses no packages that are not relevant to the question. So you should make one. – David Carlisle Apr 2 '13 at 10:57
• Got it, editing right away. – Mario S. E. Apr 2 '13 at 11:11

It worked for me without error, if it doesn't work for you you need to make an example that shows the problem.

\documentclass{article}

\usepackage{multirow}
\usepackage{array}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{arydshln}

\begin{document}
Hello.

\begin{table}\tiny
\caption{Muscles of the thigh}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\begin{tabularx}{\textwidth}{YYYYY}
Muscle & Origin & Insertion& Nerve & Action \\
\firsthline\\
\textbf{Anterior Compartment}   & & &   &   \\[3mm]

Rectus Femoris: anterior inferior iliac spine. Vastus Lateralis: greater trochanter and linea aspera of femur. Vastus Intermedius: body of femur.  Vastus Medialis: linea aspera of femur                &
Patella and onto tibial tuberosity through patellar ligament        &
Femoral                                                                                                                 &
Extends knee; rectus femoris also flexes hip\\\\

Sartorius                                                                                                               &
Anterior superiro iliac spine                                                                       &
Medial side of tibial tuberosity                                                                &
Femoral                                                                                                                 &
Flexes hip and knee; rotates thigh laterally and leg medially\\\\

\hdashline\\% I want this line to be dashed
\textbf{Medial Compartment} & & &   &   \\[3mm]

Pubis                                                                                                                       &
Pectineal line and linea aspera of femur                                                &
Obturator                                                                                                               &
Adducts, laterally rotates thigh; flexes hip\\\\

Pubis                                                                                                                       &
Linea aspera of femur                                                                                       &
Obturator                                                                                                               &
Adducts, laterally rotates thigh; flexes hip\\\\

\lasthline\\
\end{tabularx}
\label{tab:ThighMuscles2}
\end{table}

\end{document}


With the updated example using longtabu It works if you change longtabu to longtable The tabu package has some nice ideas but unfortunately it incorrectly defines the standard latex array package >{..} syntax (This is an intentional, documented feature of the package, not a bug as such) and has other incompatibilities, so often you need to go "the tabu way" and just use the features of that package or use a combination of packages that are designed to cooperate and not clash when used at the same time.

• I got what causes the error! I know I shouldn't be happy (since I haven't found a solution), but at least now I know how to replicate it: It happens when you use one of these tables with the longtable environment along in the same project. I'm not sure why. I'll edit my post to show how this happens when both tables are used. – Mario S. E. Apr 2 '13 at 11:50
• @MarioS.E. This is why we always ask people to put a complete example that shows the problem – David Carlisle Apr 2 '13 at 11:57
• I know, I'm very sorry; but it was also very difficult for me to actually find it. As you can imagine, my work at this point is full of tables, and I had no clue where to start. I just had a hunch to start commenting all the "tabu"'s. @Jon pointed my out a few hours ago that the author of tabu is building a new version that is not going to be backwards compatible, so I panicked and start changing everything. – Mario S. E. Apr 2 '13 at 12:03
• I added some notes re tabu – David Carlisle Apr 2 '13 at 12:05
• Not too sure why---I didn't check it, but is in the hyperef hot list. Correct loading order is \usepackage{longtable} \usepacakge{hyperref} \usepackage{arydshln} – Yiannis Lazarides Apr 2 '13 at 12:52