Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a file with some consecutive tables one for each month. The listoftables takes up too much space when it lists each table entry on a separate line. I can use multicols to have a two column output for the whole list of tables, however I do not want to do this for all the tables. How can I get, say, three column output in the list of table for certain range of tables?

The output for list of tables I am trying to get to (preferably first one):

1.1 Table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 January . . . 2    1.3 February  . . 2    1.4 March . . . . 2
1.5 April . . . . 3    1.6 May . . . . . 3    1.7 June  . . . . 3
1.8 July  . . . . 3
1.9 More tables . . . . . . . . . . . . . . . . . . . . . . . . 3

1.1 More tables from next chapter . . . . . . . . . . . . . . . 4

or

1.1 Table . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 January . . . 2    1.5 April . . . . 3    1.8 July  . . . . 3
1.3 February  . . 2    1.6 May . . . . . 3
1.4 March . . . . 2    1.7 June  . . . . 3
1.9 More tables . . . . . . . . . . . . . . . . . . . . . . . . 3

2.1 More tables from next chapter . . . . . . . . . . . . . . . 4

My current hackish solution using addtocontents "almost" works but, other than obvious issues with alignment and dot spacing, it is not flexible if I want to switch between two-, three- or four-column layout. And more importantly it is not automatic.

Also I am not sure how to suppress the list of table entry for particular table. I tried caption* with caption package but that did not work. I am guessing it has something to do with memoir class.

Sample output

\documentclass[oneside]{memoir}
\usepackage{hyperref}
\usepackage{multicol}

\newcommand{\threecoltab}[3]{%
\begin{tabularx}{\linewidth}{XXX} #1 & #2 & #3 \end{tabularx}}

\newcommand{\spaceddotfill}[0]{{} \dotfill \hspace{1.5em}}
\newcommand{\lotcontent}[6]{\noindent%
    \hyperref[#2]{#1} \spaceddotfill{} \pageref{#2} \hspace{1em}%
    \hyperref[#4]{#3} \spaceddotfill{} \pageref{#4} \hspace{1em}%
    \hyperref[#6]{#5} \spaceddotfill{} \pageref{#6} \newline}

\begin{document}

\listoftables
% \begin{multicols}{2}  \listoftables   \end{multicols}

\chapter{Records}
\begin{table}[htp] \caption{Table}       \label{tab:t1} \end{table}
\begin{table}[htp] \caption{January}     \label{tab:m1} \end{table}
\begin{table}[htp] \caption{February}    \label{tab:m2} \end{table}
\begin{table}[htp] \caption{March}       \label{tab:m3} \end{table}
\begin{table}[htp] \caption{April}       \label{tab:m4} \end{table}
\begin{table}[htp] \caption{May}         \label{tab:m5} \end{table}
\begin{table}[htp] \caption{June}        \label{tab:m6} \end{table}
\begin{table}[htp] \caption{July}        \label{tab:m7} \end{table}

\begin{table}[htp] \caption{More tables} \label{tab:t2} \end{table}

\addtocontents{lot}{\noindent
    \hyperref[tab:m1]{January}  \spaceddotfill{} \pageref{tab:m1} \hspace{1em}
    \hyperref[tab:m2]{February} \spaceddotfill{} \pageref{tab:m2} \hspace{1em}
    \hyperref[tab:m3]{March}    \spaceddotfill{} \pageref{tab:m3} \newline}

\addtocontents{lot}{\lotcontent{January}{tab:m1}{February}{tab:m2}{March}{tab:m3}}
\addtocontents{lot}{\lotcontent{April}{tab:m4}{May}{tab:m5}{June}{tab:m6}}
% \addtocontents{lot}{\lotcontent{July}{tab:m7}{}{}{}{}}
\addtocontents{lot}{\noindent
    \hyperref[tab:m7]{July}  \spaceddotfill{} \pageref{tab:m7} }

%\addtocontents{lot}{\threecoltab{\hyperref[tab:m1]{January}}{\hyperref[tab:m2]{February}}{\hyperref[tab:m3]{March}}}

\chapter{Data}
\begin{table}[htp] \caption{Table from next chapter} \label{tab:t3} \end{table}

\end{document}
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

enter image description here

\documentclass[oneside]{memoir}
\usepackage{hyperref}
\usepackage{multicol}


\let\oldcontentsline\contentsline



%non hyperref version
\def\mcontentsline#1#2#3#4{%
\ifvmode\noindent\else\unskip\hspace{1em plus 2pt}\fi
\hbox{\vbox{\hsize=\dimexpr(\hsize-#1em+1em)/#1\relax
\oldcontentsline{#2}{#3}{#4}}}}

\def\mcontentsline#1#2#3#4#5{%
\ifvmode\noindent\else\unskip\hspace{1em plus 2pt}\fi
\hbox{\vbox{\hsize=\dimexpr(\hsize-#1em+1em)/#1\relax
\oldcontentsline{#2}{#3}{#4}{#5}}}}

\protected\def\ltcols#1{%
\ifnum#1=1
\par\let\contentsline\oldcontentsline
\else
\par\def\contentsline{\mcontentsline{#1}}%
\fi}



\begin{document}

\listoftables


\chapter{Records}
\begin{table}[htp] \caption{Table}       \label{tab:t1} \end{table}
\begin{table}[htp] \addtocontents{lot}{\ltcols{3}}\caption{January}\label{tab:m1} \end{table}
\begin{table}[htp] \caption{February}    \label{tab:m2} \end{table}
\begin{table}[htp] \caption{March}       \label{tab:m3} \end{table}
\begin{table}[htp] \caption{April}       \label{tab:m4} \end{table}
\begin{table}[htp] \caption{May}         \label{tab:m5} \end{table}
\begin{table}[htp] \caption{June}        \label{tab:m6} \end{table}
\begin{table}[htp] \caption{July}        \label{tab:m7} \end{table}


\begin{table}[htp] \addtocontents{lot}{\ltcols{1}}\caption{More tables} \label{tab:t2} \end{table}



\chapter{Data}
\begin{table}[htp] \caption{Table from next chapter} \label{tab:t3} \end{table}

\end{document}
share|improve this answer
    
this is so much better. thank you. –  mythealias Nov 25 '12 at 5:40
    
memoir inserts some vertical space in list of tables, when changing chapter, by adding entry \addvspace{10pt} to .lot file. This causes error when compiling if the list of tables entry is not switched back to oldcontentsline. I was able to get around the problem by removing the empty space by specifying \renewcommand{\insertchapterspace}{}, as suggested in the manual. To keep the space on can do something like, \renewcommand{\insertchapterspace}{ \addtocontents{lof}{\protect\addvspace{10pt}} \addtocontents{lot}{\protect\ltcols{1}\addvspace{10pt}} } –  mythealias Nov 25 '12 at 6:37
    
Yes that's why for 1 the definition I gave switches back the definition rather than just using the paragraph version with full width setting. although probably in a real case you would want to switch after the last table in the previous chapter so your addition looks good –  David Carlisle Nov 25 '12 at 10:37
    
I ran into two issues and need help. 1. If I remove the hyperref package, I get an error Argument of \mcontentsline has an extra }. This is not a big concern as I mostly use hyperref. ''2''. If I do not have enough tables to list in a row then the alignment is off. For example if I comment out the tables for June and July from current example then the table for May is listed in the last column instead of the middle one. I tried playing with the hfill argument, but did not get much far. –  mythealias Dec 1 '12 at 21:02
    
fixed to account for the fact that with three columns you have 2 1em spaces rather than 3, also version for no hyperref added (4 arguments rather than 5, just comment out the hyperref (2nd) version of mcontentsline if you remove hyperref and delete the .lot file –  David Carlisle Dec 1 '12 at 23:44
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.