# Add a vertical line between chapters/sections and page number in ToC

In a document using the memoir class, I am trying to draw a vertical line down the whole table between the page number and text.

My requirements (so far only one remains, which is the question):

• Have no Chapter or Section Numbers (just the text) (OK)
• Have the page number to the left, the item text to the right (OK)
• Allow a slightly different style between Chapter and Section texts (OK)
• A vertical line between the two <= NOT OK

This is what I have with my MWE:

But I have no idea how to create the vertical line in such a way as to be the exact height of the table of contents (which will potentially span more than one page)

My MWE:

\documentclass{memoir}

% Clear Chapter and Section numbers
\renewcommand\chapternumberline[1]{}
\renewcommand\numberline[1]{}

% Prepare a length to indent the lot
\newlength\ToCindent
\setlength\ToCindent{0.3\textwidth}

\makeatletter

% Put pagenumbers and item texts where they should go
\newcommand*{\l@mytocentry}[3]{%
\bigskip
\par%
\noindent\parbox[c]{\ToCindent}{\makebox[\dimexpr\ToCindent-2em][r]{\Large#2}\hfill}%
\parbox[c]{\dimexpr\textwidth-\ToCindent\relax}{#1}%
}

% Create the items (with different styles)
\renewcommand*{\l@chapter}[2]{%
\l@mytocentry{\Huge#1}{#2}{\chaptername}%
}
\renewcommand*{\l@section}[2]{%
\l@mytocentry{\Large#1}{#2}{\sectionname}%
}
\makeatother

\begin{document}
\frontmatter%
\tableofcontents*

\mainmatter%

\chapter{Welcome}
\section{A Section}
\section{Another Section}
\chapter{Hello}
\section{Yet another section}
\section{Yet another section}
\chapter{World}
\section{Yet another section}

\end{document}
enter code here


I've tried:

• Making a table with pages in one column, text in the other and a vertical line between, but I can only get each line, and don't know how to loop through them to put the page number to one side, the text to another - in any case I'm hesitant to try because I'm afraid it would be reinventing the wheel
• Inspired by this question I've gotten this far but have no idea how to do the line...

These questions helped me get this far but I haven't found one that allows this vertical line I need:

# Update:

The accepted answer resolved my question. For completeness, here is how I ended up implementing it to ensure the line was centered. (I added a variable to mytocentry and added the line between my elements)

\newcommand{\vertrule}{$\smash{\rule[-2.3em]{0.2mm}{13mm}}$}
\newcommand*{\l@mytocentry}[3]{%
\bigskip
\par%
\noindent\parbox[c]{\ToCindent}{\makebox[\dimexpr\ToCindent-1em][r]{\Large#2}\hfill}%
\parbox[c]{1em}{\vertrule\hfill}%
\parbox[c]{\dimexpr\textwidth-\ToCindent\relax}{#1}%
}


Try this revised version of your MWE (for which thank you).

% memtocprob.tex SE 547344

\documentclass{memoir}

% Clear Chapter and Section numbers
\renewcommand\chapternumberline[1]{}
\renewcommand\numberline[1]{}

% Prepare a length to indent the lot
\newlength\ToCindent
\setlength\ToCindent{0.3\textwidth}

\makeatletter

% Put pagenumbers and item texts where they should go
\newcommand*{\l@mytocentry}[3]{%
\bigskip
\par%
\noindent\parbox[c]{\ToCindent}{\makebox[\dimexpr\ToCindent-2em][r]{\Large#2}\hfill}%
\parbox[c]{\dimexpr\textwidth-\ToCindent\relax}{#1}%
}

\newcommand{\myrule}{$\smash{\rule[-2mm]{1mm}{10mm}}$ } % PW ADDED

% Create the items (with different styles)
\renewcommand*{\l@chapter}[2]{%
\l@mytocentry{\Huge \myrule #1}{#2}{\chaptername}% % PW MODIFIED
}
\renewcommand*{\l@section}[2]{%
\l@mytocentry{\Large \myrule #1}{#2}{\sectionname}% % PW MODIFIED
}
\makeatother

\begin{document}
\frontmatter%
\tableofcontents*

\mainmatter%

\chapter{Welcome}
\section{A Section}
\section{Another Section}
\chapter{Hello}
\section{Yet another section}
\section{Yet another section}
\chapter{World}
\section{Yet another section}

\end{document}


The \rule macro draws a rule of the given dimension, possibly raised or lowered (as in the above case). \smash is a TeX mathmode macro that makes TeX think that its argument takes no vertical space. I have put these together before the chapter and section titles are printed in the ToC. Change the placement and size of the vertical rules to suit.

• Just tested, rather than adding \myrule into the variable (this put the line right up against the text) I added a third variable to mytocentry: \noindent\parbox[c]{\ToCindent} {\makebox[\dimexpr\ToCindent-1em][r]{\Large#2}\hfill}%\parbox[c]{1em}{\vertrule\hfill}% \parbox[c]{\dimexpr\textwidth-\ToCindent\relax}{#1} Works a charm, thank you very much! Jun 1 '20 at 17:40