4

I want to use a TikZ element to place absolutely on the page. Unfortunately, no matter what I do, the TikZ picture is treated like a character, which causes it to be treated like a paragraph when not placed in another paragraph.

I am aware of the following question, but their solutions do not work here (unless I missed something):

Minimal example

\documentclass{article}
\usepackage{tikz}

\begin{document}
\section{Some section}
\subsection{Some subsection}%
\tikz[remember picture,overlay,baseline]{\node at (current page.center){bla};}%
\begin{quote}
    This text has too much distance to the subsection heading.
\end{quote}
\end{document}

Output of minimal example

Note the big gap before the text. It disappears if I remove the TikZ command. (The text “bla” placed by TikZ is not visible in the example, but it is not of concern here.)

Of course, in this minimal example, I could just place the TikZ picture after the quote, but my actual situation is more complex, involving some macros and similar, which makes moving the TikZ command no generally applicable solution. If it helps, just imagine that the entire quote environment is dynamically via \input and the \section and \subsection commands must not be touched.

  • Your node appears in the page center, so I'm not sure what is not working for you. – Alenanno Jan 30 '16 at 14:42
  • @Alenanno: Please see my edit. – Wrzlprmft Jan 30 '16 at 14:47
  • \subsection[Some subsection]{Some subsection\tikz[...]{...;}} – egreg Jan 30 '16 at 15:35
  • The problem is that the \tikz object comes between the title and the quote, so both the spacing after the title and before the quote are added, not just the maximum between the two. – egreg Jan 30 '16 at 15:37
  • @egreg: I understand that and acknowledged it in the last paragraph of the question. As for your solution: *shudder* – Wrzlprmft Jan 30 '16 at 15:53
1

Even though you're using remember picture,overlay, TikZ still leaves a zero dimensional \hbox after the section commands which results in the start of a paragraph before your quote environment.

You can achieve the same effect by writing:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\section{Some section}
\subsection{Some subsection}%\tikz[remember picture,overlay,baseline]{\node at (current page.center){bla};}%
\mbox{}%
\begin{quote}
    This text has too much distance to the subsection heading.
\end{quote}
\end{document}

I would recommend placing the TikZ picture call some place where it will not create such an extraneous paragraph.

\documentclass{article}
\usepackage{tikz}
\begin{document}

\section{Some section}
\subsection{Some subsection}%
\begin{quote}
    \tikz[remember picture,overlay,baseline]{\node at (current page.center){bla};}%
    This text has too much distance to the subsection heading.
\end{quote}
\end{document}

which results in

enter image description here

  • I would recommend placing the TikZ picture call some place where it will not create such an extraneous paragraph. – That’s why I wrote in the question: “Note that in this case, I could place the TikZ picture after the quote, but my actual situation is more complex, involving some macros and similar, which makes this no generally applicable solution.” – Wrzlprmft Jan 30 '16 at 15:52
  • @Wrzlprmft Then perhaps you could update your MWE to better reflect the sort of situation you're dealing with. – A.Ellett Jan 30 '16 at 15:53
  • See the edit to my question. – Wrzlprmft Jan 30 '16 at 16:02
1

You can use \everypar:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\section{Some section}
\subsection[Some subsection]{Some subsection}

\everypar=\expandafter{%
  \the\everypar\tikz[remember picture,overlay,baseline]{\node at (current page.center){bla};}%
  \everypar={}}

\begin{quote}
    This text has too much distance to the subsection heading.
\end{quote}
\subsection{Some subsection}
\begin{quote}
    This text has too much distance to the subsection heading.
\end{quote}
\end{document}

enter image description here

  • Thank you for your answer. While I hope I understand what you are trying to do, I cannot get \everypar to do anything except by using \let and similar as in this answer. However with this I cannot get the autoremoving of the TikZ command to work, causing the “bla” to be placed on the page multiple times. – Wrzlprmft Jan 30 '16 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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