Question
How can I keep the current page nodes aligned with the same physical corners of the page in a document where the main layout is portrait, but some pages with longtable
are in the landscape
environment. In other words, how can I rotate the nodes clockwise like the header, body, margin, and footer. The nodes are from the packages tikz
and tikzpagenodes
.
Related Questions
- TikZ: anchors of special node “current page” seem to be incorrect in landscape
- pdflscape and tikzpagenodes problem
- Using tikzexternalize with pdflscape results in rotated image
- Should I prefer {pdflscape} over [pdftex]{lscape}?
- rotating vs lscape vs pdflscape
Example
I want to essentially be able to rotate the tikz nodes clockwise without changing the anchor names. In other words, the reference names north west, north, north east, east, south east, south, south west, west
should still refer to the same locations as for a portrait page. (In the code below, the showboxes
output should be rotated with the page.)
Desired Result:
- I want to be able to draw lines around the sections without worrying about alignment in landscape or portrait. (just like I don't have to worry about the header or footer being correctly aligned: remember that the physical page will be portrait in the book; just the body will be rotated.)
- I want the blue bar to be at the same physical location on every page of my book to indicate that that page has the start of a section on it.
Sample Code
\documentclass{article}
\usepackage{fontspec}
\usepackage[%
a4paper,
% includeheadfoot,
head=1.5cm,%\baselineskip, % distance from bottom of header to block of text aka \headsep e.g. \baselineskip
foot=1.5cm, % distance from top of footer to block of text aka \footskip
headheight=12pt, % height for the header block (no equivalent for footer)
% heightrounded, % ensure an integer number of lines
marginparwidth=2cm, % right marginal note width
marginparsep=2mm, % distance from text block to marginal note box
% height=\textheight, % height of the text block
% width=\textwidth, % width of the text block
top=2.5cm, % distance of the text block from the top of the page
bottom=3cm,
left=2.5cm,
right=2.5cm,
% showframe, % show the main blocks
% verbose, % show the values of the parameters in the log file
]{geometry}
\usepackage{pdflscape}
\usepackage{tikz} % Absolute positioning, advanced vector graphics
\usepackage{tikzpagenodes} % Adds nodes around page boxes (e.g. body)
\usetikzlibrary{calc,positioning,decorations} % Extensions for tikz (increase compilation time)
% Title Packages
\usepackage[compact,explicit,noindentafter]{titlesec}
\usepackage[rightlabels,dotinlabels]{titletoc}
\usepackage{tocloft}
\usepackage{needspace}
\usepackage{fancyhdr}
\usepackage{longtable}
% TikZ Definitions
\newcommand{\tikztitlenumber}[1]{%
\begin{tikzpicture}[remember picture, overlay,baseline]
\node [font=\Huge\fontsize{50}{60}\selectfont,text=blue,anchor=south east,inner sep=0pt, outer sep=0pt] (titlenumber) {#1};
\node [] (titlerighttop) at (titlenumber.north -| current page.east) {};
\node [] (titlerightbottom) at (titlenode -| current page.east) {};
\path [fill=blue] (titlerighttop.north) rectangle ($ (titlerightbottom) + (-2mm,0mm) $);
\end{tikzpicture}}
\newcommand{\marginmark}[1]{%
\tikz[overlay,remember picture] \node [minimum height=2cm,anchor=west,rotate=90, color=gray] at (current page marginpar area.south) {\fontsize{20}{30}\selectfont #1}; }
\newcommand{\tikztitleline}{%
\begin{tikzpicture}[overlay,remember picture]
\draw (titlenode.west) -- (titlenode -| current page text area.north east);
\end{tikzpicture}
}%
% TITLE FORMATTING
\titleformat{\section}[hang]{\needspace{6cm}\color{blue}\Huge\bfseries}{}{0pt}{\tikz[remember picture,overlay] \node [anchor=base west,yshift=-4mm] (titlenode) {};#1\hfill\tikztitlenumber{\thesection}}[\thispagestyle{sectionpage}\tikztitleline]
\titlespacing{\section}{0pt}{40pt}{20pt}
\newcommand{\showboxes}{%
\begin{tikzpicture}[remember picture,overlay]
\draw [red] (current page text area.south west) rectangle
(current page text area.north east);
\draw [green] (current page header area.south west) rectangle
(current page header area.north east);
\draw [blue] (current page footer area.south west) rectangle
(current page footer area.north east);
\draw [black] (current page marginpar area.south west) rectangle
(current page marginpar area.north east);
\end{tikzpicture}
}%
\fancypagestyle{sectionpage}
{
\fancyhf{} % clear all fields
\renewcommand{\headrulewidth}{0pt}
\lhead{}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{%
\begin{minipage}[m]{.3\textwidth}
\begin{flushright}
\bfseries\footnotesize \thepage
\end{flushright}
\end{minipage}
\marginmark{}
}%
}%
\usepackage{lipsum}
\begin{document}
\section{Portrait Section}
\showboxes{}
\lipsum
\begin{landscape}
\showboxes{}
\section{Landscape Section}
\begin{longtable}{|l|p{6cm}|p{11cm}|p{4cm}|} \hline
\label{Table:references}
\textcolor{blue}{\textbf{Nr.}} & \textcolor{blue}{\textbf{Start of Clause}} & \textcolor{blue}{\textbf{Info}} & \textcolor{blue}{\textbf{End of Clause}}\\ \hline
[1] & These numbers & A whole lotta info & are not in order. \\ \hline
[2] & These numbers & A whole lotta info & are not in order. \\ \hline
[3] & These numbers & A whole lotta info & are not in order. \\ \hline
[4] & These numbers & A whole lotta info & are not in order. \\ \hline
[5] & These numbers & A whole lotta info & are not in order. \\ \hline
[6] & These numbers & A whole lotta info & are not in order. \\ \hline
[7] & These numbers & A whole lotta info & are not in order. \\ \hline
[8] & These numbers & A whole lotta info & are not in order. \\ \hline
[9] & These numbers & A whole lotta info & are not in order. \\ \hline
[10] & These numbers & A whole lotta info & are not in order. \\ \hline
[11] & These numbers & A whole lotta info & are not in order. \\ \hline
[14] & These numbers & A whole lotta info & are not in order. \\ \hline
[15] & These numbers & A whole lotta info & are not in order. \\ \hline
[16] & These numbers & A whole lotta info & are not in order. \\ \hline
[17] & These numbers & A whole lotta info & are not in order. \\ \hline
[19] & These numbers & A whole lotta info & are not in order. \\ \hline
[20] & These numbers & A whole lotta info & are not in order. \\ \hline
[21] & These numbers & A whole lotta info & are not in order. \\ \hline
[22] & These numbers & A whole lotta info & are not in order. \\ \hline
[23] & These numbers & A whole lotta info & are not in order. \\ \hline
[24] & These numbers & A whole lotta info & are not in order. \\ \hline
\end{longtable}
\end{landscape}
\end{document}
Output
Honing in on the Problem
Reduced Minimal Working Example according to Gonzalo
\documentclass{article}
\usepackage{pdflscape}
\usepackage{tikzpagenodes}
\usepackage{lipsum}
\newcommand{\showboxes}{%
\begin{tikzpicture}[remember picture,overlay]
\draw [red] (current page text area.south west) rectangle
(current page text area.north east);
\draw [green] (current page header area.south west) rectangle
(current page header area.north east);
\draw [blue] (current page footer area.south west) rectangle
(current page footer area.north east);
\draw [black] (current page marginpar area.south west) rectangle
(current page marginpar area.north east);
\end{tikzpicture}
}
\begin{document}
\section{Portrait Section}
\showboxes{}
\lipsum[4]
\begin{landscape}
\showboxes{}
\section{Landscape Section}
\lipsum[4]
\end{landscape}
\end{document}
\fancypagestyle{sectionpage}{...}
to check if it is relevant for the problem? Did you try to remove the longtable to test if it is relevant? Sorry but you are hiding behind a "I'm so helpless"-argument.\titleformat
and test if it is relevant. Sorry but the fact that you could get it wrong and perhaps remove something relevant is not an excuse not to try it at all.