# Changing vertical alignment of items in middle of line (for ToC entry)

Well, I'm really starting to hate LaTeX sometimes - mostly because you can't really learn one thing, and have it applied everywhere else you wanted :/

For instance, I asked the question Changing minipage vertical alignment in mid-line?, which got an answer that works in that context - but which I simply cannot apply in this context now, even if I have the same problem.

\documentclass{book}

\usepackage{hyperref}
\usepackage{tocloft}

% like definition for \phantomsection, but for part
% "Re: documentation for \phantomsection"
% http://newsgroups.derkeiler.com/Archive/Comp/comp.text.tex/2006-01/msg01612.html
\makeatletter
\def\phantompart{%
\stepcounter{part}%
\xdef\@currentHref{part.\thepart}%
}
\makeatother

% tocloft custom TOC entry format:
\renewcommand{\cftpartpresnum}{ \fbox{ Entry } }
\renewcommand{\cftpartfont}{\normalfont}
\fboxsep=0pt % for framebox

\begin{document}

\tableofcontents

\phantompart %
\protect\contentsline{part}{%
\thepart\hspace{1em}\ignorespaces %
\fbox{ %
A Short Entry %
} %
} %
{ \fbox{ \thepage } }
{ \fbox{ part.\thepart } }% fbox doesn't show!
} %

\phantompart %
\protect\contentsline{part}{%
\thepart\hspace{1em}\ignorespaces %
\fbox{ %
\protect\begin{minipage}{0.5\textwidth} %
\textbf{A longer entry here...} \\ %
Maybe something more written in this entry here, %
just to show as an illustration ... %
\protect\end{minipage} %
} %
} %
{ \fbox{ \thepage } }
{ \fbox{ part.\thepart } }% fbox doesn't show!
} %

\phantompart %
\protect\contentsline{part}{%
\thepart\hspace{1em}\ignorespaces %
\fbox{ %
\protect\begin{minipage}{0.5\textwidth} %
\textbf{Another longer entry here...} \\ %
Still, some more content entered here; %
just to show as an illustration ... %
\protect\end{minipage} %
} %
} %
{ \fbox{ \thepage } }
{ \fbox{ part.\thepart } }% fbox doesn't show!
} %

\vspace{0.2\textheight}
Some extra text...

\end{document}


The output of this example is as such:

Apparently, the entries in the table of contents are typeset as "one line", the minipages being treated as characters - and all "characters" being centrally vertically aligned.

What I want is the same as in the initial question: I want the "Entry" and the title (minipage) top-aligned - and the title (minipage) and the page number bottom aligned.

I guess this means introducing a "soft" line break of sorts - as an instruction only for change of vertical alignment: that subsequent words should be aligned to the bottom of the previous word (but without actually creating the extra baseline skip [and starting again to position the words from the left margin] as with a real, "hard" line break).

Composed in an image editor, the desired output would look like this:

... but I simply cannot see what changes can I make to the code to implement this. If we go as per the initial question - where would I insert the tabular environments, to implement the "soft" line break?

If there is a package that addresses this, I'd love to hear about it; but otherwise I'd be more interested in hearing a "core" method to solve this.

-
You should have a look at the titletoc package (bundled with titlesec and sharing the manual): on page 14 there's precisely the example you want. –  egreg Jun 9 '12 at 10:49
Many thanks, @egreg - indeed, page 14 does have that example (note to self: but it's showed as \texttt, not as an image; look up "If you have seen tocs, the latter should be familiar to you...") ... However, now I'd have to change all my templates etc :( - so, I'd still be interested in hearing a Latex solution to the posting as stated (with tocloft); hopefully I learn more about vertical alignment of items on lines ... Cheers! –  sdaau Jun 9 '12 at 10:56
@egreg - this w. titletoc not trivial at all; I have been trying to make something like that for hours now, and no dice; posted on Understanding titletoc example (and vertical alignment on line). Cheers! –  sdaau Jun 9 '12 at 13:31
And just wanted to say that I got to some sort of a (complicated) solution with \titletoc, posted in this answer; however, since this question is about \tocloft, I hope it's OK to also keep it open, until an answer arrives for it... –  sdaau Jun 10 '12 at 2:17
When you add a [t] to your minipages, everything gets alined to the first line. I personally prefer that to having the page numbers aligned to the last line ... of course this is not the solution to your problem. –  Sebastian Nov 19 at 10:02

Please forgive my LaTeX-noobness, I started using it, recently. Have you tried something like this?

\addcontentsline{toc}{part}{\textbf{A longer entry here...} \\
Maybe something more written in this entry here, \\
just to show as an illustration ...}


I mean, without using the mini-page? I don't recognize all the code you use between {part} and the minipage so, possibly, it won't work the way you want, but I just wanted to help.

-
I mean no offense, but this is (by admission) not really an answer. People sometimes put this kind of response in a comment (which I think you need a few more rep points to do), but as a rule, if you know it doesn't work, you shouldn't post it. This site is not a discussion forum. Nonetheless, welcome, and please enjoy reading the other questions and answers, which will definitely teach you a lot. –  Ryan Reich Jun 17 '12 at 18:24
Many thanks for the answer, @Aerxis - I haven't tried it, but I'm pretty sure it won't work for me (I can guess that all the lines will be bottom aligned - I want top/top/bottom alignment in the same line). I generally managed to fix that with a different package in Understanding titletoc example (and vertical alignment on line) - but it is far from trivial. Cheers! –  sdaau Jun 17 '12 at 18:26