如何打印像标签列表这样的部分标题?

如何打印像标签列表这样的部分标题?

我可以创建一个右侧有多个部分(如多选项卡)的用户手册吗?

像这样:

演示

-- 我想也许我可以通过 tikz 模板化页面。(如果可能的话,这将非常灵活)所以我添加了 tikz 标签。

答案1

这是一个可能的选项,使用background放置边框、标签和页码的包:

\documentclass{article}
\usepackage[a5paper,vmargin=2cm]{geometry}
\usepackage{background}
\usepackage{etoolbox}
\usepackage{totcount}
\usepackage{lipsum}

% to have access to the total number of sections
\regtotcounter{section}

% every section starts on a new page
\pretocmd{\section}{\clearpage}{}{}

% auxiliary lengths for the height of the frame and the width of each tab
\newlength\mylen
\newlength\mylena

% style for the section tabs
\tikzset{tab/.style={
  text width=\mylena,anchor=south,
  draw=gray,thick,rectangle,rounded corners=12pt,rotate=270,
  align=center,text height=20pt,
  text depth=25pt,inner sep=0pt,fill=gray!20,
  yshift=-18pt,font=\sffamily\LARGE}}
% style for the current section tab
\tikzset{selectedtab/.style={tab,color=white,fill=gray!90}}

% the page number is showed in the background material
\pagestyle{empty}

\AtBeginDocument{
% calculation of the width for each tab
\setlength\mylen{\dimexpr\textheight+2cm\relax}
\ifnum\totvalue{section}>0
\setlength\mylena{\dimexpr\mylen/\totvalue{section}\relax}
\fi

% the main part; as background material we place the border, 
% the section (current and other) tabs and the page number 
\backgroundsetup{
scale=1,
color=black,
angle=0,
opacity=1,
contents= {
  \begin{tikzpicture}[remember picture, overlay]
  \node[inner sep=0pt,text width=\the\dimexpr\textwidth+1.5cm\relax] 
    at (current page.center) (border) {\rule{0pt}{\dimexpr\textheight+2cm\relax}};
  \foreach \valsection in {0,...,\numexpr\totvalue{section}-1\relax}
  {
    \node[\ifnum\thesection<\numexpr\valsection+1\relax tab\else \ifnum\thesection>\numexpr\valsection+1\relax tab\else selectedtab\fi\fi,xshift=(0.5+\valsection)*\mylena] 
      at (border.north east) (tab-\valsection) {Section \the\numexpr\valsection+1\relax};
  }
  \node[draw=gray,line width=2pt,rectangle,rounded corners=10pt,inner sep=0pt,
    text width=\the\dimexpr\textwidth+1.5cm\relax,fill=white] 
    at (current page.center) {\rule{0pt}{\dimexpr\textheight+2cm\relax}};
  \node[font=\LARGE\sffamily,fill=white] 
    at (border.south) {\makebox[3em][c]{\thepage}};
\end{tikzpicture}}
  }
}

\begin{document}

\section{Test Section One}
\lipsum[1-3]
\section{Test Section Two}
\lipsum[1-3]
\section{Test Section Three}
\lipsum[1-3]
\section{Test Section Four}
\lipsum[2]

\end{document}

在此处输入图片描述

该文件需要处理三次。

如果该包的最新版本background不可用,则使用版本 1.0 的语法的代码如下:

\documentclass{article}
\usepackage[a5paper,vmargin=2cm]{geometry}
\usepackage{background}
\usepackage{etoolbox}
\usepackage{totcount}
\usepackage{lipsum}

% to have access to the total number of sections
\regtotcounter{section}

% every section starts on a new page
\pretocmd{\section}{\clearpage}{}{}

% auxiliary lengths for the height of the frame and the width of each tab
\newlength\mylen
\newlength\mylena

% style for the section tabs
\tikzset{tab/.style={
  text width=\mylena,anchor=south,
  draw=gray,thick,rectangle,rounded corners=12pt,rotate=270,
  align=center,text height=20pt,
  text depth=25pt,inner sep=0pt,fill=gray!20,
  yshift=-18pt,font=\sffamily\LARGE}}
% style for the current section tab
\tikzset{selectedtab/.style={tab,color=white,fill=gray!90}}

% the page number is showed in the background material
\pagestyle{empty}

\AtBeginDocument{
% calculation of the width for each tab
\setlength\mylen{\dimexpr\textheight+2cm\relax}
\ifnum\totvalue{section}>0
\setlength\mylena{\dimexpr\mylen/\totvalue{section}\relax}
\fi

% the main part; as background material we place the border, 
% the section (current and other) tabs and the page number 
\SetBgScale{1}
\SetBgColor{black}
\SetBgAngle{0}
\SetBgOpacity{1}
\SetBgContents{
  \begin{tikzpicture}[remember picture, overlay]
  \node[inner sep=0pt,text width=\the\dimexpr\textwidth+1.5cm\relax] 
    at (current page.center) (border) {\rule{0pt}{\dimexpr\textheight+2cm\relax}};
  \foreach \valsection in {0,...,\numexpr\totvalue{section}-1\relax}
  {
    \node[\ifnum\thesection<\numexpr\valsection+1\relax tab\else \ifnum\thesection>\numexpr\valsection+1\relax tab\else selectedtab\fi\fi,xshift=(0.5+\valsection)*\mylena] 
      at (border.north east) (tab-\valsection) {Section \the\numexpr\valsection+1\relax};
  }
  \node[draw=gray,line width=2pt,rectangle,rounded corners=10pt,inner sep=0pt,
    text width=\the\dimexpr\textwidth+1.5cm\relax,fill=white] 
    at (current page.center) {\rule{0pt}{\dimexpr\textheight+2cm\relax}};
  \node[font=\LARGE\sffamily,fill=white] 
    at (border.south) {\makebox[3em][c]{\thepage}};
\end{tikzpicture}}
}

\begin{document}

\section{Test Section One}
\lipsum[1-3]
\section{Test Section Two}
\lipsum[1-3]
\section{Test Section Three}
\lipsum[1-3]
\section{Test Section Four}
\lipsum[2]

\end{document}

答案2

这是基于@Gonzalo Medina 的回答的另一个建议,但使用该scrlayer包来定义图层页面样式:

\documentclass{article}
\usepackage[a5paper,vmargin=2cm]{geometry}
\usepackage{tikz}% loads also xcolor and graphicx
\usepackage{totcount}
\usepackage{lipsum}% for dummy text
\usepackage{etoolbox}

% to have access to the total number of sections
\regtotcounter{section}

% every section starts on a new page
\pretocmd{\section}{\clearpage}{}{}

% auxiliary length for the width of each tab
\newlength\mylena

\tikzset{
  tab/.style={% style for the section tabs
    text width=\mylena,
    draw=gray,
    thick,
    rectangle,
    rounded corners=12pt,
    align=center,
    text width=53pt,
    inner sep=0pt,
    fill=gray!20,
    font=\sffamily\LARGE,
    overlay
  },
  selectedtab/.style={% style for the current section tab
    tab,
    color=gray!90,
    text=white
  },
  pagenumber/.style={% style for the page number
    font=\LARGE\sffamily,
    fill=white,
    text width=3em,
    align=center
  }
}

\usepackage{scrlayer}
\DeclarePageStyleByLayers{border}{border.odd,border.even}
\pagestyle{border}

\DeclareNewLayer[
  background,
  oddpage,
  textarea,
  addvoffset=-1cm,
  addhoffset=-.75cm,
  addheight=2cm,
  addwidth=1.5cm,
  contents={%
  \ifnum\totvalue{section}>0
    \setlength\mylena{\dimexpr\layerheight/\totvalue{section}\relax}%
  \fi
    \begin{tikzpicture}
      \pgfdeclarelayer{background}
      \pgfsetlayers{background,main}
      \node[
        draw=gray,
        fill=white,
        inner sep=0pt,
        minimum width=\layerwidth-\pgflinewidth,
        minimum height=\layerheight-\pgflinewidth,
        rounded corners=10pt,
        line width=2pt
      ](border){};
      \node[pagenumber]at (border.south){\thepage};
      \begin{pgfonlayer}{background}
        \foreach \valsection in {0,...,\numexpr\totvalue{section}-1\relax}{%
          \node[
            \ifnum\value{section}<\numexpr\valsection+1\relax 
              tab%
            \else 
              \ifnum\value{section}>\numexpr\valsection+1\relax 
                tab%
              \else
                selectedtab%
              \fi
            \fi,
            minimum height=\mylena-\pgflinewidth
          ] at ([yshift=-(0.5+\valsection)*\mylena]border.north east)
          {%
            \hspace*{25pt}\rotatebox{-90}{Section \the\numexpr\valsection+1\relax}%
          };
        }
      \end{pgfonlayer}
    \end{tikzpicture}%
  }
]{border.odd}

\DeclareNewLayer[
  clone=border.odd,
  evenpage,
  contents={%
    \begin{tikzpicture}
      \node[
        draw=gray,
        fill=white,
        inner sep=0pt,
        minimum width=\layerwidth-\pgflinewidth,
        minimum height=\layerheight-\pgflinewidth,
        rounded corners=10pt,
        line width=2pt
      ](border){};
      \node[pagenumber]at (border.south){\thepage};
    \end{tikzpicture}%
  }
]{border.even}

\begin{document}
\section{Test Section One}
\lipsum[1-3]
\section{Test Section Two}
\lipsum[1-3]
\section{Test Section Three}
\lipsum[1-3]
\section{Test Section Four}
\lipsum[1-5]
\end{document}

运行两次即可获得

在此处输入图片描述

如上例所示,可以为偶数页和奇数页定义不同的层。对于双面文章

\documentclass[twoside]{article}

上面的例子导致

在此处输入图片描述

相关内容