删除空白页中的垂直文本

删除空白页中的垂直文本

我已经在这个论坛上问过这个问题,(我想在目录页以外的所有页边距上放置一个垂直方向的句子),他们给了我一个完美的解决方案,但现在我想在目录页和空白页以外的所有页边距上放置一个垂直方向的句子。此代码不会从空白页中删除垂直文本。

\documentclass[12pt,a4paper,twoside,openright]{book}
\usepackage[utf8]{inputenc}
\usepackage[frenchb]{babel}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{eso-pic}

\makeatletter
\newlength\@tempdim@x
\newlength\@tempdim@y
% structure des commandes :
%   #1 = deplacement selon x
%   #2 = deplacement selon y
%   #3 = texte à mettre
\newcommand\AtUpperLeftCorner[3]{%
\begingroup
\@tempdim@x=0cm
\@tempdim@y=\paperheight
\advance\@tempdim@x#1
\advance\@tempdim@y-#2
\put(\LenToUnit{\@tempdim@x},\LenToUnit{\@tempdim@y}){#3}%
\endgroup
}
\newcommand\AtUpperRightCorner[3]{%
\begingroup
\@tempdim@x=\paperwidth
\@tempdim@y=\paperheight
\advance\@tempdim@x-#1
\advance\@tempdim@y-#2
\put(\LenToUnit{\@tempdim@x},\LenToUnit{\@tempdim@y}){#3}%
\endgroup
}
\newcommand\AtLowerLeftCorner[3]{%
\begingroup
\@tempdim@x=0cm
\@tempdim@y=0cm
\advance\@tempdim@x#1
\advance\@tempdim@y#2
\put(\LenToUnit{\@tempdim@x},\LenToUnit{\@tempdim@y}){#3}%
\endgroup
}
\newcommand\AtLowerRightCorner[3]{%
\begingroup
\@tempdim@x=\paperwidth
\@tempdim@y=0cm
\advance\@tempdim@x-#1
\advance\@tempdim@y#2
\put(\LenToUnit{\@tempdim@x},\LenToUnit{\@tempdim@y}){#3}%
\endgroup
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start edit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\iftoc 

\AddToShipoutPicture{%
    \AtLowerRightCorner{2cm}{5cm}{\ifodd\c@page\iftoc\else \rotatebox{90}{Good \raisebox{0.1ex}{--} My book}\fi\fi}
    \AtLowerLeftCorner{2cm}{5cm}{\ifodd\c@page\else\iftoc\else \rotatebox{90}{Good \raisebox{0.1ex}{--} My book}\fi\fi}
}
\makeatother

\pagenumbering{roman}
\begin{document}
    {\pagestyle{plain}
    \global\toctrue% or place outside braces
    \tableofcontents}

\chapter{Chapter one}\tocfalse
\pagenumbering{arabic}
\section{one}
\lipsum[2-10]
\section{two}
\lipsum[4]
\section{three}
\lipsum[11]
\chapter{Chapter two}
\section{four}
\lipsum[1]

\end{document}

答案1

开始解决您的问题---您的MWE的修订版本:

% verticaltextprob.tex SE 546962

\documentclass[12pt,a4paper,twoside,openright]{book}
\usepackage[utf8]{inputenc}
\usepackage[frenchb]{babel}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{eso-pic}

\makeatletter
\newlength\@tempdim@x
\newlength\@tempdim@y
% structure des commandes :
%   #1 = deplacement selon x
%   #2 = deplacement selon y
%   #3 = texte à mettre
\newcommand\AtUpperLeftCorner[3]{%
\begingroup
\@tempdim@x=0cm
\@tempdim@y=\paperheight
\advance\@tempdim@x#1
\advance\@tempdim@y-#2
\put(\LenToUnit{\@tempdim@x},\LenToUnit{\@tempdim@y}){#3}%
\endgroup
}
\newcommand\AtUpperRightCorner[3]{%
\begingroup
\@tempdim@x=\paperwidth
\@tempdim@y=\paperheight
\advance\@tempdim@x-#1
\advance\@tempdim@y-#2
\put(\LenToUnit{\@tempdim@x},\LenToUnit{\@tempdim@y}){#3}%
\endgroup
}
\newcommand\AtLowerLeftCorner[3]{%
\begingroup
\@tempdim@x=0cm
\@tempdim@y=0cm
\advance\@tempdim@x#1
\advance\@tempdim@y#2
\put(\LenToUnit{\@tempdim@x},\LenToUnit{\@tempdim@y}){#3}%
\endgroup
}
\newcommand\AtLowerRightCorner[3]{%
\begingroup
\@tempdim@x=\paperwidth
\@tempdim@y=0cm
\advance\@tempdim@x-#1
\advance\@tempdim@y#2
\put(\LenToUnit{\@tempdim@x},\LenToUnit{\@tempdim@y}){#3}%
\endgroup
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start edit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\iftoc 

\AddToShipoutPicture{%
    \AtLowerRightCorner{2cm}{5cm}{\ifodd\c@page\iftoc\else \rotatebox{90}{Good \raisebox{0.1ex}{--} My book}\fi\fi}
    \AtLowerLeftCorner{2cm}{5cm}{\ifodd\c@page\else\iftoc\else \rotatebox{90}{Good \raisebox{0.1ex}{--} My book}\fi\fi}
}
\makeatother

\pagenumbering{roman}
\begin{document}
    {\pagestyle{plain}
    \global\toctrue% or place outside braces
    \tableofcontents}

\chapter{Chapter one}\tocfalse
\pagenumbering{arabic}
\section{one}
\lipsum[2-10]
\section{two}
\lipsum[4]
\section{three}
\lipsum[11]
pagetotal = \the\pagetotal % the amount of text on the page
\clearpage
pagetotal = \the\pagetotal
\ifdim\pagetotal=0pt\toctrue\fi % if not text (an empty page) don't print vertical text
\chapter{Chapter two}
\tocfalse % switch vertical text back on
\section{four}
\lipsum[1]

\end{document}

我过去常常\pagetotal查看页面是否为空,如果是,则设置\toctrue为防止打印垂直文本。这在 MWE 中有效。但是,您如何决定何时检查空白页以及如何在一般情况下自动将垂直文本切换回打开状态?

在您的“答案”中,实际上是一个新问题,您希望一切都是自动的。我已经修改了我的原始 MWE,如下所示,它会自动删除空白页上的垂直文本。

% verticaltextprob2.tex SE 546962

\documentclass[12pt,a4paper,twoside,openright]{book}
\usepackage[utf8]{inputenc}
\usepackage[frenchb]{babel}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{eso-pic}

\makeatletter
\newlength\@tempdim@x
\newlength\@tempdim@y
% structure des commandes :
%   #1 = deplacement selon x
%   #2 = deplacement selon y
%   #3 = texte à mettre
\newcommand\AtUpperLeftCorner[3]{%
\begingroup
\@tempdim@x=0cm
\@tempdim@y=\paperheight
\advance\@tempdim@x#1
\advance\@tempdim@y-#2
\put(\LenToUnit{\@tempdim@x},\LenToUnit{\@tempdim@y}){#3}%
\endgroup
}
\newcommand\AtUpperRightCorner[3]{%
\begingroup
\@tempdim@x=\paperwidth
\@tempdim@y=\paperheight
\advance\@tempdim@x-#1
\advance\@tempdim@y-#2
\put(\LenToUnit{\@tempdim@x},\LenToUnit{\@tempdim@y}){#3}%
\endgroup
}
\newcommand\AtLowerLeftCorner[3]{%
\begingroup
\@tempdim@x=0cm
\@tempdim@y=0cm
\advance\@tempdim@x#1
\advance\@tempdim@y#2
\put(\LenToUnit{\@tempdim@x},\LenToUnit{\@tempdim@y}){#3}%
\endgroup
}
\newcommand\AtLowerRightCorner[3]{%
\begingroup
\@tempdim@x=\paperwidth
\@tempdim@y=0cm
\advance\@tempdim@x-#1
\advance\@tempdim@y#2
\put(\LenToUnit{\@tempdim@x},\LenToUnit{\@tempdim@y}){#3}%
\endgroup
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start edit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\iftoc 

\AddToShipoutPicture{%
%  pagetotal = \the\pagetotal
  \ifdim\pagetotal=12.0pt\else    %  new code ---------------------------
    \AtLowerRightCorner{2cm}{5cm}{\ifodd\c@page\iftoc\else \rotatebox{90}{Good \raisebox{0.1ex}{--} My book}\fi\fi}
    \AtLowerLeftCorner{2cm}{5cm}{\ifodd\c@page\else\iftoc\else \rotatebox{90}{Good \raisebox{0.1ex}{--} My book}\fi\fi}
  \fi
}
\makeatother

\pagenumbering{roman}
\begin{document}
    {\pagestyle{plain}
    \global\toctrue% or place outside braces
    \tableofcontents}

\chapter{Chapter one}\tocfalse
\pagenumbering{arabic}
\section{one}
\lipsum[2-10]
\section{two}
\lipsum[4]
\section{three}
\lipsum[11]
%pagetotal = \the\pagetotal % the amount of text on the page
\clearpage
%pagetotal = \the\pagetotal
%\ifdim\pagetotal=0pt\toctrue\fi % if not text (an empty page) don't print vertical text
\chapter{Chapter two}
%\tocfalse
\section{four}
\lipsum[1]
\cleardoublepage
\lipsum[2]

\end{document}

您可能需要更改行的长度

\ifdim\pagetotal=12.0pt\else

以适合您的最终文档(我尝试过\baselineskip12.0pt没有成功)。

相关内容