问题

问题

问题

如何保持当前页面节点与相同的身体的在文档中,页面的角落主要布局为纵向,但有些页面longtablelandscape环境中。换句话说,我如何才能顺时针旋转节点,如页眉、正文、边距和页脚。节点来自包tikztikzpagenodes

相关问题

例子

我希望能够顺时针旋转 tikz 节点而不更改锚点名称。换句话说,引用名称north west, north, north east, east, south east, south, south west, west仍应指向与纵向页面相同的位置。(在下面的代码中,输出showboxes应随页面旋转。)

期望结果:

  1. 我希望能够在各个部分周围画线而不必担心横向或纵向的对齐。(就像我不必担心页眉或页脚是否正确对齐一样:请记住书中的物理页面将是纵向的;只是正文会旋转。)
  2. 我希望蓝色条出现在书的每一页上的相同物理位置,以指示该页面上某个章节的开始。

示例代码

\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}

输出

第 1 页 第2页

深入研究问题

根据 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}

答案1

如果您想要让页面节点精确地位于纵向位置(旋转除外),您可以使用以下命令。

\documentclass{article}
%\usepackage{fontspec}
\usepackage[%
     letterpaper,
 %   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,
%     twoside
%     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
\usetikzlibrary{calc,positioning,decorations} % Extensions for tikz (increase compilation time)
\usepackage{tikzpagenodes} % Adds nodes around page boxes (e.g. body)
\usepackage{fancyhdr}
\usepackage[compact,explicit,noindentafter]{titlesec}
\usepackage[rightlabels,dotinlabels]{titletoc}
\usepackage{tocloft}
\usepackage{needspace}
\usepackage{lipsum}

\makeatletter
\newif\if@landscape% add test for landscape mode
\@landscapefalse
\let\old@landscape=\landscape
\def\landscape{\@landscapetrue\old@landscape}
\let\old@endlandscape=\endlandscape
\def\endlandscape{\old@endlandscape
\@landscapefalse}

\expandafter\def\csname pgf@sh@np@current page\endcsname{%
\if@landscape
  \def\southwest{\pgfpointorigin}%
  \def\northeast{\pgfpoint{\pgfsys@thepageheight}{\pgfsys@thepagewidth}}%
\else
  \def\southwest{\pgfpointorigin}%
  \def\northeast{\pgfpoint{\pgfsys@thepagewidth}{\pgfsys@thepageheight}}%
\fi}
\expandafter\def\csname pgf@sh@nt@current page\endcsname{%
\if@landscape{1}{0}{0}{1}{\dimexpr\paperwidth-2.17in}{.5cm}%
\else{1}{0}{0}{1}{0pt}{0pt}%
\fi}
\def\pgf@sh@nt@pagenodes{%
\if@landscape{0}{-1}{1}{0}{\dimexpr\paperheight-2.17in}{\dimexpr\paperwidth+0.5cm}%
\else{1}{0}{0}{1}{0pt}{0pt}%
\fi}
\def\@newtikzpagenode#1{%
    \expandafter\let\csname pgf@sh@ns@#1\expandafter\endcsname\csname pgf@sh@ns@current page\endcsname
    \expandafter\let\csname pgf@sh@nt@#1\endcsname\pgf@sh@nt@pagenodes
    \expandafter\let\csname pgf@sh@pi@#1\expandafter\endcsname\csname pgf@sh@pi@current page\endcsname
    \expandafter\def\csname pgf@sh@np@#1\endcsname
}
\@newtikzpagenode{current page text area}{%
\if@landscape
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperwidth-\current@textarea@top-\linewidth}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperwidth-\current@textarea@top}}%
\else
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperheight-\current@textarea@top}}%
\fi}
\@newtikzpagenode{current page header area}{%
\if@landscape
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperwidth-\current@textarea@top+\headsep}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperwidth-\current@textarea@top+\headsep+\headheight}}%
\else
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperheight-\current@textarea@top+\headsep}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperheight-\current@textarea@top+\headsep+\headheight}}%
\fi}
\@newtikzpagenode{current page footer area}{%
\if@landscape
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperwidth-\current@textarea@top-\linewidth-\footskip}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperwidth-\current@textarea@top-\linewidth-\footskip+\headheight}}%
\else
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperheight-\current@textarea@top-\textheight-\footskip}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperheight-\current@textarea@top-\textheight-\footskip+\headheight}}%
\fi}
\@newtikzpagenode{current page marginpar area}{%
\if@landscape
    \def\southwest{\pgfpoint
        {\current@textarea@left\ifoddpageoroneside+\textwidth+\marginparsep\else-\marginparsep-\marginparwidth\fi}%
        {\paperwidth-\current@textarea@top-\linewidth}%
    }%
    \def\northeast{\pgfpoint
        {\current@textarea@left\ifoddpageoroneside+\textwidth+\marginparsep+\marginparwidth\else-\marginparsep\fi}%
        {\paperwidth-\current@textarea@top}%
    }%
\else
    \def\southwest{\pgfpoint
        {\current@textarea@left\ifoddpageoroneside+\textwidth+\marginparsep\else-\marginparsep-\marginparwidth\fi}%
        {\paperheight-\current@textarea@top-\textheight}%
    }%
    \def\northeast{\pgfpoint
        {\current@textarea@left\ifoddpageoroneside+\textwidth+\marginparsep+\marginparwidth\else-\marginparsep\fi}%
        {\paperheight-\current@textarea@top}%
    }%
\fi}
\newcommand{\lsrotate}{\if@landscape 90\else 0\fi}
%\tikzset{every node/.style={rotate=\lsrotate}}% this will also affect nodes in the text area
\makeatother

% 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{}
    }%
}%

\begin{document}
\begin{landscape}
\section{Landscape Section}
\showboxes{}
\lipsum[1-4]
\begin{tikzpicture}
\node{normal tikzpicture};
\end{tikzpicture}
\end{landscape}
\section{Portrait Section}
\showboxes{}
\lipsum[1-4]
\begin{tikzpicture}
\node{normal tikzpicture};
\end{tikzpicture}
\end{document}

备用页面节点

答案2

我在到达列节点之前就退出了。仍然不知道为什么需要 0.5 厘米。

\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,
%     twoside
%     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
\usetikzlibrary{calc,positioning,decorations} % Extensions for tikz (increase compilation time)
\usepackage{tikzpagenodes} % Adds nodes around page boxes (e.g. body)

\makeatletter
\newif\if@landscape% add test for landscape mode
\@landscapefalse
\let\old@landscape=\landscape
\def\landscape{\@landscapetrue\old@landscape}
\let\old@endlandscape=\endlandscape
\def\endlandscape{\old@endlandscape\@landscapefalse}

\expandafter\def\csname pgf@sh@np@current page\endcsname{%
\if@landscape
  \def\southwest{\pgfpointorigin}%
  \def\northeast{\pgfpoint{\pgfsys@thepageheight}{\pgfsys@thepagewidth}}%
\else
  \def\southwest{\pgfpointorigin}%
  \def\northeast{\pgfpoint{\pgfsys@thepagewidth}{\pgfsys@thepageheight}}%
\fi}
\expandafter\def\csname pgf@sh@nt@current page\endcsname{%
\if@landscape{1}{0}{0}{1}{\dimexpr\paperwidth-2.17in}{.5cm}%
\else{1}{0}{0}{1}{0pt}{0pt}%
\fi}
\def\pgf@sh@nt@pagenodes{%
\if@landscape{1}{0}{0}{1}{\dimexpr\paperwidth-1.97in}{.5cm}%
\else{1}{0}{0}{1}{0pt}{0pt}%
\fi}
\def\@newtikzpagenode#1{%
    \expandafter\let\csname pgf@sh@ns@#1\expandafter\endcsname\csname pgf@sh@ns@current page\endcsname
    \expandafter\let\csname pgf@sh@nt@#1\endcsname\pgf@sh@nt@pagenodes
    \expandafter\let\csname pgf@sh@pi@#1\expandafter\endcsname\csname pgf@sh@pi@current page\endcsname
    \expandafter\def\csname pgf@sh@np@#1\endcsname
}
\@newtikzpagenode{current page text area}{%
\if@landscape
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperwidth-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\linewidth}{\paperwidth-\current@textarea@top}}%
\else
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperheight-\current@textarea@top-\textheight}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperheight-\current@textarea@top}}%
\fi}
\@newtikzpagenode{current page header area}{%
\if@landscape
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperwidth-\current@textarea@top+\headsep}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\linewidth}{\paperwidth-\current@textarea@top+\headsep+\headheight}}%
\else
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperheight-\current@textarea@top+\headsep}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperheight-\current@textarea@top+\headsep+\headheight}}%
\fi}
\@newtikzpagenode{current page footer area}{%
\if@landscape
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperwidth-\current@textarea@top-\textheight-\footskip}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\linewidth}{\paperwidth-\current@textarea@top-\textheight-\footskip+\headheight}}%
\else
    \def\southwest{\pgfpoint{\current@textarea@left}{\paperheight-\current@textarea@top-\textheight-\footskip}}%
    \def\northeast{\pgfpoint{\current@textarea@left+\textwidth}{\paperheight-\current@textarea@top-\textheight-\footskip+\headheight}}%
\fi}
\@newtikzpagenode{current page marginpar area}{%
\if@landscape
    \def\southwest{\pgfpoint
        {\current@textarea@left\ifoddpageoroneside+\linewidth+\marginparsep\else-\marginparsep-\marginparwidth\fi}%
        {\paperwidth-\current@textarea@top-\textheight}%
    }%
    \def\northeast{\pgfpoint
        {\current@textarea@left\ifoddpageoroneside+\linewidth+\marginparsep+\marginparwidth\else-\marginparsep\fi}%
        {\paperwidth-\current@textarea@top}%
    }%
\else
    \def\southwest{\pgfpoint
        {\current@textarea@left\ifoddpageoroneside+\textwidth+\marginparsep\else-\marginparsep-\marginparwidth\fi}%
        {\paperheight-\current@textarea@top-\textheight}%
    }%
    \def\northeast{\pgfpoint
        {\current@textarea@left\ifoddpageoroneside+\textwidth+\marginparsep+\marginparwidth\else-\marginparsep\fi}%
        {\paperheight-\current@textarea@top}%
    }%
\fi}
\makeatother

\begin{document}
\begin{landscape}
\begin{tikzpicture}[remember picture,overlay,ultra thick]% draw nodes
\draw[red] (current page.south west) -- (current page.north east);
\draw (current page.north west) -- (current page.south east);
\draw[green] (current page header area.south west) rectangle (current page header area.north east);
\draw[red] (current page text area.south west) rectangle (current page text area.north east);
\draw[blue] (current page footer area.south west) rectangle (current page footer area.north east);
\draw[gray] (current page marginpar area.south west) rectangle (current page marginpar area.north east);
\end{tikzpicture}
\end{document}

景观页面节点

答案3

显然,页面节点和 pdflscape 不能协同工作。Heiko 或许可以提出解决方案。作为替代方案,您可以更改页面布局,例如使用 KOMA 类:

\documentclass[pagesize]{scrartcl}

\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);
    \draw [yellow,<->]  (current page.south west)-- (current page.north east) ;
\end{tikzpicture}
}

\begin{document}
\section{Portrait Section}
\showboxes{}
\lipsum[4]
\newpage
\KOMAoptions{paper=landscape}
\recalctypearea
\showboxes{}
\section{Landscape Section}
\lipsum[4]

\end{document}

缺点是它也会改变页脚的位置 - 如果不想这样,就必须在这些页面上安装一些特殊的页面样式。

相关内容