页边距上的垂直句子

页边距上的垂直句子

我正在写一份文档,我想在目录页以外的所有页边距上放置一个垂直方向的句子。

我的代码是:

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

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

\pagenumbering{roman}
\begin{document}
    {\pagestyle{plain}
    \tableofcontents}

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

\end{document}

在此处输入图片描述

答案1

您可以将 if 与页面的值一起放置:

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

如果您愿意,您可以定义一个计数器并将其设置为打印目录后的页码,然后添加该值以自动化该过程(可能会稍微复杂一些,因为目录是在第二次编译后打印的)。

编辑:(解决这个问题的办法mainmatter

\newcounter{realpage}

\AddToShipoutPicture{%
\AtLowerRightCorner{2cm}{5cm}{\ifodd\c@page\ifnum\value{realpage}>0 \rotatebox{90}{Good \raisebox{0.1ex}{--} My book}\fi\fi}
\AtLowerLeftCorner{2cm}{5cm}{\ifodd\c@page\else\ifnum\value{realpage}>0 \rotatebox{90}{Good \raisebox{0.1ex}{--} My book}\fi\fi}
} 

\let\oldmainmatter\mainmatter
\def\mainmatter{\oldmainmatter\stepcounter{realpage}}

最后编辑:

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

\newcounter{realpage}

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

\pagenumbering{roman}
\begin{document}
    {\pagestyle{plain}
    \tableofcontents}



\chapter{Chapter one}
\stepcounter{realpage}
\pagenumbering{arabic}
\section{one}
\lipsum[2]
\section{two}
\lipsum[4]
\section{three}
\lipsum[11]
\chapter{Chapter two}
\section{four}
\lipsum[1]

\end{document}

使用相同的序言...为了在目录之后的可能为空白的页面中打印垂直文本,请像这样使用:

\begin{document}
    {\pagestyle{plain}
    \tableofcontents}
    \clearpage
    \stepcounter{realpage}

\chapter{Chapter one}

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

\end{document}

答案2

您还可以手动设置标志来打开或关闭覆盖。

\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]
\section{two}
\lipsum[4]
\section{three}
\lipsum[11]
\chapter{Chapter two}
\section{four}
\lipsum[1]

\end{document}

相关内容