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.

Wrzlprmft
  • 759
  • 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
  • I don't see that your edit really clarifies anything. Your MWE seems to suggest that the TikZ picture could go anywhere in the document as long as it lands on the proper page. It's hard to find a solution to a situation where you essentially say, "it must be here!", and where you don't really give us much more to work with. Without further details on what LaTeX/TeX's digestive tract has to deal with between the sectioning commands and the quote environment, I'm at a loss of what to recommend – A.Ellett Jan 30 '16 at 16:10
  • @A.Ellett: The quote environment is just an example for what could cause problems with such a TikZ command (because a regular paragraph wouldn’t do). If it helps, that I want to define a \newcommand containing the TikZ command that can be placed (e.g., by another user who cannot be bothered with this stuff) at every reasonable position (i.e., not within other commands) without breaking the layout. – Wrzlprmft Jan 30 '16 at 17:08

2 Answers2

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

A.Ellett
  • 50,533
  • 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

egreg
  • 1,121,712
  • 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