2

I want to set a decorated page number packing in the the Tikz node with the use of \AtBeginShipout macro, but when a lstlisting environment with basicstyle option seting font to \ttfamily breaks between pages some of font features of the page number has no proper effect; in my example it's bold!

The following code shows the problem, and it'll be produced with both pdflatex and xelatex.

\documentclass{article}
\usepackage{atbegshi}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{listings}

\AtBeginShipout{\AtBeginShipoutAddToBox{%
\begin{tikzpicture}[remember picture, overlay,]
            \node [draw, circle, color=gray, yshift=2cm] at (current page.south){\textbf{\LARGE\thepage}};
\end{tikzpicture}%
}}

\pagestyle{empty}

\lstset{ basicstyle=\color{black}\ttfamily\small,
    frameround=tftf,    frame=ltbr,}

\begin{document}
\lipsum[1-4]
\begin{lstlisting}
print ('hello worlds')

print ('hello worlds')

print ('hello worlds')

print ('hello worlds')

print ('hello worlds')

print ('hello worlds')
\end{lstlisting}
\lipsum
\end{document}

The first page number isn't bold:

enter image description here

while the second one is OK (has bold face).

enter image description here

1 Answer 1

2

Your tikzpicture seems to use the current font at the end of the page. At the end of your first page, the current font is \ttfamily\small (as specified in your ltlisting environment).

As workaround, you may add \rmfamily to your node (and use the font key):

\documentclass{article}
\usepackage{atbegshi}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{listings}

\AtBeginShipout{\AtBeginShipoutAddToBox{%
\begin{tikzpicture}[remember picture, overlay,]
  \node [draw, circle, color=gray, yshift=2cm,font=\rmfamily\bfseries\Large]
  at (current page.south){\thepage};
\end{tikzpicture}%
}}

\pagestyle{empty}

\lstset{ basicstyle=\color{black}\ttfamily\small,
    frameround=tftf,    frame=ltbr,}

\begin{document}
\lipsum[1-4]
\begin{lstlisting}
print ('hello worlds')

print ('hello worlds')

print ('hello worlds')

print ('hello worlds')

print ('hello worlds')

print ('hello worlds')
\end{lstlisting}
\lipsum
\end{document}

You must log in to answer this question.

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