0

I'm trying to customize a template, in which the following snipet generates a "mini table of contents" respect to the book's part which is created.

\node[anchor=south east,inner xsep=1.7cm,inner ysep=.5cm,fill=black] 
at (\paperwidth-1cm,-\paperheight+1cm) {
    \parbox[t][][t]{8.5cm}{\printcontents{l}{0}{\setcounter{tocdepth}{1}}%
}};

I want to know if is possible to calculate the size of that node or the text inside it, because I want to add a fancy detail, another node which act as a "glass", in addition it is for practical purposes, some images I include as bg images have white color tones, with the automatization I have done is too complex to manage externally the fonts color.

Edit

I found a way to overcome, the problem was the next:

I used The Legrand Orange Book template for creating a book, I had modified the part headings in the structure.tex document. (The code is so large, but here is the main part)

{\thispagestyle{empty}%
    \begin{tikzpicture}[remember picture,overlay]%
    \node at (current page.north west){\begin{tikzpicture}[remember picture,overlay]%    
        \node [anchor=north west,inner sep=0pt] at (0,0) {\noindent\makebox[\paperwidth]{\includegraphics[width=\paperwidth,height=\paperheight]{\thepartimage}}};%THE PART IMAGE (a Background image)
        
        \node[anchor=south east,fill=black,fill opacity=0.3] at (\paperwidth,-\paperheight) {\parbox{\paperwidth}{
            \hfill \vspace*{\paperheight}
        }};%The Glassy effect (Or Opaccity)
        
        \node[anchor=north] at (4cm,-3.25cm){\color{white}\fontsize{200}{100}\sffamily\bfseries\thepart}; %PART NUMBER (e.g III)
        
        \node[anchor=north east] at (\paperwidth-1cm,-3.1cm){\parbox[t][][t]{15cm}{\centering\strut\raggedleft\color{white}\fontsize{55}{55}\sffamily\bfseries#2}};%PART NAME (e.g Theoretical Infrastructure)
        
        \node[anchor=south east,inner xsep=0.6cm] (chapterminicontents) at (\paperwidth-1cm,-\paperheight+1cm){\parbox[t][][t]{8.5cm}{
                \printcontents{l}{0}{\setcounter{tocdepth}{1}}
        }};%Minicontents index (all the chapters in this part)
    \end{tikzpicture}};
\end{tikzpicture}}%

This modification allows to surpass two problems, if the selected BG Picture and the font (as in my case) are white, it polarizes the BG and allows to can read the part title and minicontents.

Why I was trying to calculate the size of a node?

It is because I wanted to create the glassy effect to apply it over the minicontents table.

Finally

Thanks for your time and help.

5
  • Welcome! Yes, it is possible to measure the size of a node. Load \usetikzlibrary{calc}, give the node a name: \node[anchor=south east,inner xsep=1.7cm,inner ysep=.5cm,fill=black] (tocnode) at (\paperwidth-1cm,-\paperheight+1cm) { \parbox[t][][t]{8.5cm}{\printcontents{l}{0}{\setcounter{tocdepth}{1}}% }}; and use \path let \p1=($(tocnode.north east)-(tocnode.south west)$) in .... Then you can use the dimensions of the node, which get stored in \x1 and \y1 in .... An explicit answer will require an explicit minimal working example from your side.
    – user194703
    Commented Dec 19, 2019 at 18:26
  • Hi, Thank you, I'm trying to use your recommendation but I can't figure out how to use \x1, \y1. I can't understand why you use in since it is used in loops. Commented Dec 19, 2019 at 19:11
  • 1
    Please provide a complete example that starts with \documentclass and ends with \end{document}. Then it is much easier to provide an explicit and self-contained example. (It may well be that you do not even need to compute the dimensions explicitly for your use case.)
    – user194703
    Commented Dec 19, 2019 at 19:15
  • 1
    in is also used for the let syntax, described in chapter 14.15 of the manual. Commented Dec 19, 2019 at 21:48
  • 1
    The best way to measure the contents of the node is to first create it as a savebox and use \ht \dp and \wd for the height (above baseline), depth (below baseline) and width, then put \usebox into the node. A named node can be measured using \pgfextractx and \pgfextracty along with \pgfpointdiff and \pgfpointanchor. Commented Dec 19, 2019 at 21:50

1 Answer 1

1

If you only need a glassy background, it suffices to add something like

fill=gray,fill opacity=0.3,text opacity=1

to the node. For this application you do not have to measure the size of the node explicitly. This is an attempt to reconstruct the setup you are describing.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[overlay,remember picture]
 \node[anchor=south east] at ([xshift=-5cm,yshift=2.5cm]current page.south east)
 {\includegraphics{example-image-duck}};
 \node[anchor=south east,text width=8.5cm,
 fill=gray,fill opacity=0.3,text opacity=1,text=white,inner sep=1em] at ([xshift=-1cm,yshift=1cm]current page.south east)
 {\vspace*{-2\baselineskip}\tableofcontents};
\end{tikzpicture}
\section{Purr}
\section{Hibernate}
\section{Pft}
\end{document}

enter image description here

If you need to know the dimensions, you can use the calc library.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[overlay,remember picture]
 \node[anchor=south east] at ([xshift=-5cm,yshift=2.5cm]current page.south east)
 {\includegraphics{example-image-duck}};
 \node[anchor=south east,text width=8.5cm,
 fill=gray,fill opacity=0.3,text opacity=1,text=white,inner sep=1em] (tocnode)
 at ([xshift=-1cm,yshift=1cm]current page.south east)
 {\vspace*{-2\baselineskip}\tableofcontents};
 \path let \p1=($(tocnode.north east)-(tocnode.south west)$) in
  (tocnode.north) node[above=1cm,text width=5cm,draw,fill=white] {The node \texttt{tocnode}
  is \x1\ wide and \y1\ tall.};
\end{tikzpicture}
\section{Purr}
\section{Hibernate}
\section{Pft}
\end{document}

enter image description here

Other options to make white text on a white background visible include the usage of the contour package.

You must log in to answer this question.

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