On the question How to dynamically calculate the height of an empty list of things?, I learned I am required to now how my class calculates its contents page title in order to make the answer to works. I tried \large\contentsname\vskip\baselineskip\vskip\afterchapskip, but it was not enough, as the List of Tables is empty (there are no tables) and it should not be displayed:
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6400)
entering extended mode
(test3.tex
LaTeX2e <2017-04-15>
Babel <3.12> and hyphenation patterns for 76 language(s) loaded.
(D:\User\Documents\latex\texmfs\install\tex\latex\memoir\memoir.cls
Document Class: memoir 2016/05/16 v3.7f configurable book, report, article docu
ment class
(D:\User\Documents\latex\texmfs\install\tex\generic\oberdiek\ifpdf.sty)
(D:\User\Documents\latex\texmfs\install\tex\latex\ifetex\ifetex.sty
(D:\User\Documents\latex\texmfs\install\tex\plain\ifetex\ifetex.tex))
(D:\User\Documents\latex\texmfs\install\tex\generic\ifxetex\ifxetex.sty)
(D:\User\Documents\latex\texmfs\install\tex\generic\oberdiek\ifluatex.sty)
(D:\User\Documents\latex\texmfs\install\tex\latex\memoir\mem12.clo)) (test3.aux
) (test3.toc) (test3.lof)
The height of the list 'List of Figures' is '131.77776pt' from '67.84pt'
(test3.lot)
The height of the list 'List of Tables' is '117.27776pt' from '67.84pt'
[1{D:/User/Documents/latex/texmfs/data/pdftex/config/pdftex.map}] [2] [3]
(test3.aux) )<D:/User/Documents/latex/texmfs/install/fonts/type1/public/amsfont
s/cm/cmbx12.pfb><D:/User/Documents/latex/texmfs/install/fonts/type1/public/amsf
onts/cm/cmr12.pfb>
Output written on test3.pdf (3 pages, 23659 bytes).
Transcript written on test3.log.
How can I set \boxBforwhenlistisnotempty for memoir titles page?
\documentclass[12pt,a4paper]{memoir}
\newbox\boxAforwhenlistisnotempty
\newbox\boxBforwhenlistisnotempty
\newcommand{\whenlistisnotempty}[2]{%
\setbox\boxAforwhenlistisnotempty\vbox{#2}%
\setbox\boxBforwhenlistisnotempty\vbox{%
\large\contentsname\vskip\baselineskip\vskip\afterchapskip%
}%
\typeout{The height of the list '#1'
is '\the\ht\boxAforwhenlistisnotempty'
from '\the\ht\boxBforwhenlistisnotempty'}%
\ifdim\ht\boxAforwhenlistisnotempty>\ht\boxBforwhenlistisnotempty%
\unvbox\boxAforwhenlistisnotempty%
\fi%
}
\begin{document}
\tableofcontents
\whenlistisnotempty{\listfigurename}{
\listoffigures
}
\whenlistisnotempty{\listtablename}{
\listoftables
}
\chapter{First section}
\begin{figure}
\centering
Figure
\caption{Caption}
\end{figure}
\end{document}
References