我想要的是

我想要的是

这是上一个问题的附录:如何使用环境\draw在页码附近放置tikzpicture


我想要的是

我想将部分文本移至每页的顶部,并在其旁边放置一张图片。看看这个:

我想要的是

为什么我要提到章节?因为当文档完成时,我想在开头制作一个目录。

  • 图像(svg文件)始终相同。

例如:

  • 完整文档共有8页。
  • 第 1 页应该没有任何内容。
  • 在第 2-4 页中,绿色矩形应该包含:Section One: Text以及其旁边的图像。
  • 在第 5-7 页中,绿色矩形应该包含:Section Two: More text以及其旁边的图像。
  • 在第 8 页中,绿色矩形应该包含:Bibliography以及其旁边的图像。

我们应该能够制作包含这 3 个部分(两个部分和参考书目)的目录。

我做了什么

考虑这个 MWE(取自附录的公认答案):

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{graphicx}
\usepackage{tikz}
\usepackage[hidelinks]{hyperref}
\usepackage{lastpage}
\usepackage{refcount}
\usepackage{fancyhdr}
\pagestyle{fancy}
\newsavebox{\arrowL}
\newsavebox{\arrowR}
\sbox\arrowR{\begin{tikzpicture}
\draw[line width=1mm,white,line cap=round,line join=round] 
(0,0) -- (7pt,8pt) -- (0pt,16pt);
\end{tikzpicture}}
\sbox\arrowL{\begin{tikzpicture}
\draw[line width=1mm,white,line cap=round,line join=round] 
(0,0) -- (-7pt,8pt) -- (0pt,16pt);
\end{tikzpicture}}
\fancyhf{}
\rhead{
%\newcommand{\sec}[1]{%
\begin{tikzpicture}[remember picture,overlay]%
        \fill[green] (current page.north west) rectangle ++(\paperwidth,-1.5cm);%
        \node[text=white,anchor=west,xshift=4cm,yshift=-.75cm,font=\LARGE\bfseries] at (current page.north west) (a) {Section One: Text};%
\end{tikzpicture}%
%}
}
\rfoot{
    \begin{tikzpicture}[remember picture,overlay]
        \fill[black] (current page.south west) rectangle ++(\paperwidth,1.5cm)
        node[midway,align=center,font=\LARGE\bfseries,text=white,xscale=1.5] 
        (pageno-\number\value{page}) 
        {\thepage}; % From https://tex.stackexchange.com/a/443744/152550
        \ifnum\value{page}<\getpagerefnumber{LastPage}
         \path ([xshift=\paperwidth/4]pageno-\number\value{page}) 
            node{\hyperlink{page.\the\numexpr\value{page}+1}{\usebox\arrowR}};
        \fi
        \ifnum\value{page}>1
         \path ([xshift=-\paperwidth/4]pageno-\number\value{page}) 
            node{\hyperlink{page.\the\numexpr\value{page}-1}{\usebox\arrowL}};
        \fi % From https://tex.stackexchange.com/a/529698/152550
    \end{tikzpicture}
}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}

%\sec{Section One: Text}
\tikz\node[circle,draw,
           path picture={
               \node at (path picture bounding box.center){
                   \includegraphics[width=2.5cm]{Example.png}
               };
           }]{}; % From https://tex.stackexchange.com/a/193558/152550

Example
\newpage 
Another example

\end{document}

MWE 输出

问题:

  • 我不知道如何使用\newcommand[1]{\sec}{...}在页面上有不同的部分,其中参数是部分的名称。
  • 裁剪后的图像未显示在 2.5 厘米圆圈(内部\begin{document})上。(我已加载graphicx并放置\graphicspath。我尝试在\includegraphics{Example.png}外面tikzpicture,并且成功了。)

答案1

一种方法是使用titlesec。这样,您可以使用普通\section命令来实现此目的。这有多种优势(目录、超链接等)。然后您只需输入

\section{I am a cat}
Example
\newpage 
\section{You are a duck}
Another example

在文档正文中。

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usepackage[hidelinks]{hyperref}
\usepackage{lastpage}
\usepackage{refcount}
\usepackage{fancyhdr}
\pagestyle{fancy}
\newsavebox{\arrowL}
\newsavebox{\arrowR}
\sbox\arrowR{\begin{tikzpicture}
\draw[line width=1mm,white,line cap=round,line join=round] 
(0,0) -- (7pt,8pt) -- (0pt,16pt);
\end{tikzpicture}}
\sbox\arrowL{\begin{tikzpicture}
\draw[line width=1mm,white,line cap=round,line join=round] 
(0,0) -- (-7pt,8pt) -- (0pt,16pt);
\end{tikzpicture}}
\fancyhf{}
\titleformat{\section}[display]{}{}{0pt}
  {\begin{tikzpicture}[overlay,remember picture]
  \fill[green] (current page.north west) rectangle 
  ([yshift=-1.5cm]current page.north east);
 \node[text=white,anchor=west,font=\LARGE\bfseries\sffamily,anchor=west]  (a)
    at ([xshift=4cm,yshift=-.75cm]current page.north west)
   {Section \thesection: #1};
   \clip ([xshift=2cm,yshift=-.75cm]current page.north west)
    circle[radius=1.24cm];
   \node at 
   ([xshift=2cm,yshift=-.75cm]current page.north west)
    {\includegraphics[width=2.5cm]{example-image-duck}};
         \end{tikzpicture}
}[]

% see https://tex.stackexchange.com/a/236778
\titleformat{name=\section,numberless}[display]{}{}{0pt}
  {\begin{tikzpicture}[overlay,remember picture]
  \fill[green] (current page.north west) rectangle 
  ([yshift=-1.5cm]current page.north east);
 \node[text=white,anchor=west,font=\LARGE\bfseries\sffamily,anchor=west]  (a)
    at ([xshift=4cm,yshift=-.75cm]current page.north west)
   {#1};
   \clip ([xshift=2cm,yshift=-.75cm]current page.north west)
    circle[radius=1.24cm];
   \node at 
   ([xshift=2cm,yshift=-.75cm]current page.north west)
    {\includegraphics[width=2.5cm]{example-image-duck}};
\end{tikzpicture}
}[]


\rfoot{
    \begin{tikzpicture}[remember picture,overlay]
        \fill[black] (current page.south west) rectangle ++(\paperwidth,1.5cm)
        node[midway,align=center,font=\LARGE\bfseries,text=white,xscale=1.5] 
        (pageno-\number\value{page}) 
        {\thepage}; % From https://tex.stackexchange.com/a/443744/152550
        \ifnum\value{page}<\getpagerefnumber{LastPage}
         \path ([xshift=\paperwidth/4]pageno-\number\value{page}) 
            node{\hyperlink{page.\the\numexpr\value{page}+1}{\usebox\arrowR}};
        \fi
        \ifnum\value{page}>1
         \path ([xshift=-\paperwidth/4]pageno-\number\value{page}) 
            node{\hyperlink{page.\the\numexpr\value{page}-1}{\usebox\arrowL}};
        \fi % From https://tex.stackexchange.com/a/529698/152550
    \end{tikzpicture}
}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\begin{document}
\section{I am a cat}
Example
\newpage 
\section{You are a duck}
Another example

\newpage 
\section*{Bibliography}
A book about ducks and seven books about marmots.

\end{document}

在此处输入图片描述

人们可以轻松改变实施的细节。

相关内容