3

I just want a simple \midrule that doesn't span the entire page or cell.
For instance, with \rule, you can specify dimensions like:

\rule[0.2cm]{100pt}{0.5pt}

That's as close as I can get it, but it doesn't fit nicely in the same amount of space as \midrule, it seems to take up and extra half a line (row) or so. It has this little extra buffer of empty space, like an invisible border or something. Normally it wouldn't bother me, but I have a bit of a theme happening that took me a while to get all nice and if I neglect the uniform, it's going to make the whole thing look sloppy. Is there some way to get what I want? Below is a quick example. Notice how the \midrule is all nice and snug with the others, but the \rule is being greedy, but on the other hand, it lets me specify length manually.

enter image description here

\documentclass[margin=6]{standalone}
\usepackage{amsmath,booktabs}

\begin{document}

\begin{tabular}{c|c}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\midrule
\multicolumn{2}{c}{\scshape Bijection} \\
\midrule
\multicolumn{2}{c}{$f:V(e) \to V(c)$} \\
\midrule
\multicolumn{2}{c}{$f(e_{1})=c_{1}\ \ \ \ \ \ 
                    f(e_{2})=c_{3}\ \ \ \ \ \ 
                    f(e_{3})=c_{5}$} \\

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\midrule
\multicolumn{2}{c}{\scshape Bijection} \\
\midrule
\multicolumn{2}{c}{$f:V(e) \to V(c)$} \\
\multicolumn{2}{c}{\rule[0.2cm]{180pt}{0.5pt}} \\
\multicolumn{2}{c}{$f(e_{1})=c_{1}\ \ \ \ \ \ 
                    f(e_{2})=c_{3}\ \ \ \ \ \ 
                    f(e_{3})=c_{5}$} \\

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\midrule
\end{tabular}

\end{document}
voices
  • 2,039
  • @marmot there you go, i uploaded more info. I have tried \cmidrule but I couldn't get it to do what i want. Weird syntax too. All I want to do is set a custom line length. – voices Mar 30 '19 at 04:48

2 Answers2

5

I am using this answer to obtain

\documentclass[margin=6]{standalone}
\usepackage{amsmath,booktabs}

\begin{document}

\begin{tabular}{c|c}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\midrule
\multicolumn{2}{c}{\scshape Bijection} \\
\midrule
\multicolumn{2}{c}{$f:V(e) \to V(c)$} \\
\midrule
\multicolumn{2}{c}{$f(e_{1})=c_{1}\ \ \ \ \ \ 
                    f(e_{2})=c_{3}\ \ \ \ \ \ 
                    f(e_{3})=c_{5}$} \\

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\midrule
\multicolumn{2}{c}{\scshape Bijection} \\
\cmidrule(l{5em}r{5em}){1-2}
\multicolumn{2}{c}{$f:V(e) \to V(c)$} \\
\multicolumn{2}{c}{\rule[0.2cm]{180pt}{0.5pt}} \\
\multicolumn{2}{c}{$f(e_{1})=c_{1}\ \ \ \ \ \ 
                    f(e_{2})=c_{3}\ \ \ \ \ \ 
                    f(e_{3})=c_{5}$} \\

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\midrule
\end{tabular}
\end{document}

enter image description here

Here l{5em}r{5em} indicates that the rule gets shortened by 5em on each side.

  • Cool. What's an em? Can i set the width / weight too? – voices Mar 30 '19 at 05:09
  • @tjt263 An em is a relative unit that scales with the font size, see e.g. https://tex.stackexchange.com/a/4244/121799. And yes, you can change the line width. It is the optional argument, try e.g. \cmidrule[1.5pt](l{5em}r{5em}){1-2}, –  Mar 30 '19 at 05:18
  • Got it. \cmidrule[.5pt](l{5.5em}r{5.5em}){1-2} – voices Mar 30 '19 at 05:18
  • 1
    Same time. Thanks. – voices Mar 30 '19 at 05:19
  • Not sure why defining the table as c|c and then using \multicolumn{2}{c} for every row. – egreg Mar 30 '19 at 10:47
  • @egreg Could you please consider stopping to pick on me for things that were in the code by the OP? There could be good reasons for doing that because this might not be the complete table. In fact, if we look back, the origin of this seems to be your own answer https://tex.stackexchange.com/a/481255/121799 . Please complain there. –  Mar 30 '19 at 14:17
  • @egreg Probably because I don't know any better. Pretty much everything I do with LaTeX is reverse engineered, adapted, improvised, or otherwise hacked together from scraps of other peoples code. If I don't know an elegant way to do something, I'll just keep hacking away at it and settle for whatever yields the end result I'm looking for first. Also, like marmot said, it's not the complete table. It's just something I smashed together in a hurry to illustrate a specific problem. – voices Mar 30 '19 at 15:06
2

I may guess you want something like this. You can play with the padding of the short rule by changing 2em.

Avoid \ \ \ sequences for spacing: better using \hspace or fixed chunks such as \quad or \qquad.

\documentclass{article}
\usepackage{amsmath,booktabs}

\begin{document}

\begin{tabular}{c}
\toprule
\begin{tabular}{@{\hspace{2em}}c@{\hspace{2em}}}
  \scshape Bijection \\
  \midrule
  $f\colon V(e) \to V(c)$ \\
\end{tabular} \\
\midrule
$f(e_{1})=c_{1}$\qquad $f(e_{2})=c_{3}$\qquad $f(e_{3})=c_{5}$ \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

egreg
  • 1,121,712