1

I want to make the horizontal line of the table shorter, just aligned with the text, but do not intersect with the vertical line. How to do that? the horizontal line is marked by red

I tried to do it like this:

\documentclass{article}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{colortbl}
\usepackage{xcolor}
\begin{document}
\arrayrulecolor{lightgray}
\begin{tabularx}{\textwidth}{|Xr|}
\Xhline{0.08em}
ABC & DEF \\
\hline
HIJ & \\
 & \\
 & \\
\hline
\end{tabularx}
\end{document}

but it turns out:

enter image description here

The horizontal line just behind ABC intersects with the vertical lines. But I want the start of the horizontal line to align with A and H in the vertical direction, and the end of the horizontal line to align with F.

  • 3
    Welcome! Please provide us with an MWE, i.e. a document that starts with \documentclass and ends with \end{document}. – user121799 Jun 7 '18 at 3:26
  • 2
    You could do that with the \cmidrule command of the booktabs package. Search for that command here in TeX.SX to find some example usages. – Stefan Pinnow Jun 7 '18 at 3:40
  • I can't provide an MWE, because the table was drew in Word and I wonder how I can do that in LaTeX. The\cmidrule won't be helpful, because there is not any columns between the horizontal line and the vertical lines. – stdo Jun 7 '18 at 6:38
  • 2
    @stdo, you don't have to provide the code that produce exactly that table. Just the code you have right now, this is mainly for three reasons: 1. Prove that you at least tried to obtain that table by yourself 2. Show which package are already used in your file, in this way we don't post solutions incompatible with your packages 3. Save time, we could work on something, we didn't have to provide fake data and similar. – gvgramazio Jun 7 '18 at 8:51
  • You can try pandoc to convert your docx to tex: your table will be converted too! pandoc -s <file>.docx -o <file>.tex That'll give you a basis. – NBur Jun 7 '18 at 10:12
2

A brute force approach is to add extra columns and then use \cline (I'm assuming you meant the horizontal line below ABC).

\documentclass{article}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{colortbl}
\usepackage{xcolor}
\begin{document}
\arrayrulecolor{lightgray}
\begin{tabularx}{\textwidth}{|c@{}Xr@{}c|}
\Xhline{0.08em}
&ABC & DEF&\\ 
\cline{2-3}
&HIJ &&  \\
& &&\\
& &&\\
\hline
\end{tabularx}
\end{document}

enter image description here

  • @stdo - Happy to help! – John Jun 7 '18 at 22:29

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.