5

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.

Please consider the following MWE:

\documentclass{book}

\usepackage{hyperref}
\hypersetup{pdftex, colorlinks=true, linkcolor=black}
\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}%
 \Hy@raisedlink{\hyper@anchorstart{\@currentHref}\hyper@anchorend}%
}
\makeatother

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


\begin{document}

\tableofcontents


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

\phantompart %
\addtocontents{toc}{%
  \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 %
\addtocontents{toc}{%           % tocloft: this adds to toc, but NOT bookmark!:
  \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:

a.png

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:

a1-edited.png

... 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.

5
  • 3
    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
    Commented Jun 9, 2012 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
    Commented Jun 9, 2012 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
    Commented Jun 9, 2012 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
    Commented Jun 10, 2012 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
    Commented Nov 19, 2013 at 10:02

1 Answer 1

1

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.

2
  • 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
    Commented Jun 17, 2012 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
    Commented Jun 17, 2012 at 18:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .