# Remove \dotfill where \rule sits in particular lines/rows within \longtable environment

How could I replace \dotfill with \rule{3em}{.6pt} in some particular lines/rows?

..so it would look like this:

Item A ................ xxxxx
Item B ................ xxxxx
----- +
Item C ................ xxxxx
Item D ................ xxxxx
----- -


MWE:

\documentclass{article}
\usepackage{array,longtable,mathtools}
\begin{document}

\begin{longtable}{@{}p{5cm}<{\dotfill}@{}p{\dimexpr\linewidth-5cm}@{}}
Item A & xxxxx \\
Item B & xxxxx \\
& \rule{3em}{.6pt} $+$ \\ % remove \dotfill here
Item C & xxxxx \\
Item D & xxxxx \\
& \rule{3em}{.6pt} $-$  % remove \dotfill here
\end{longtable}

\end{document}

• If I understand well what you want, use \multicolumn{1}{c}{} for the empty cell. – Bernard Mar 10 '17 at 13:05

You could just put something invisible in the cells, so that there is no room for \dotfill to insert dots:

\documentclass{article}
\usepackage{array,longtable,mathtools}
\begin{document}

\begin{longtable}{@{}p{5cm}<{\dotfill}@{}l@{}}
Item A & xxxxx \\
Item B & xxxxx \\
\hspace*{5cm}& \rule{3em}{.6pt} $+$ \\ % remove \dotfill here
Item C & xxxxx \\
Item D & xxxxx \\
\hspace*{5cm}& \rule{3em}{.6pt} $-$  % remove \dotfill here
\end{longtable}

\end{document}


• Wow.. really smart trick! \rule{5cm}{0pt} Perfect! – guest_5758 Mar 10 '17 at 13:27
• @guest_5758 Maybe the space is safer then the rule. Who knows which pdf viewer might have problems with a 0pt rule... – user36296 Mar 10 '17 at 13:36
• @guest_5758 Your table is already centred -- but you don't see it, because your second column p{\dimexpr\linewidth-5cm} is so big, it takes all the remaining space of the line -> If you want it centred, make the second column smaller. – user36296 Mar 10 '17 at 18:46
• @guest_5758 Please see my edited code, simply let latex decide what's the best width for the column and don't try to do it manually. – user36296 Mar 11 '17 at 15:20
• @guest_5758 Not removing {\dimexpr\linewidth-5cm}, but replacing p{\dimexpr\linewidth-5cm} with l – user36296 Mar 12 '17 at 1:05

Use \multicolumn{1}{c}{}, so the \dotfill will not be inserted. I also added a trick for raising the rule to the height of the operation symbol.

\documentclass{article}
\usepackage{array,longtable,mathtools}

\makeatletter
\newcommand{\operation}[1]{%
\multicolumn{1}{c}{}&
\check@mathfonts
\rule[\dimexpr\fontdimen22\textfont2-.3pt]{3em}{.6pt} $#1$
}
\makeatother

\begin{document}

\begin{longtable}{@{}p{5cm}<{\dotfill}@{}p{\dimexpr\linewidth-5cm}@{}}
Item A & xxxxx \\
Item B & xxxxx \\
\operation{+}  \\
Item C & xxxxx \\
Item D & xxxxx \\
\operation{-}
\end{longtable}

\end{document}


• +1 for raising the rule to the height of the operation symbol. – guest_5758 Mar 11 '17 at 23:38