我想在书的外侧放置一个字母(表示字典中显示的字母),将其放在较暗的框中,并将该字母垂直放置。字典的用户以后可以通过侧面的字母划分轻松访问搜索的词条。
最小示例:
\documentclass[twocolumn]{book}
\usepackage[top=1.5cm, bottom=1.5cm, left=2cm, right=2cm]{geometry}
\usepackage{fancyhdr}
\usepackage[utf8x, utf8]{inputenc}
\usepackage[T1]{fontenc}
\newcommand\entry[3][]{\hangpara{2em}{1}{\fontfamily{phv} selectfont{\textbf{{#2}}}}\
#3\ifx\relax#1\relax\markboth{#2}{#2}\else\markboth{#1}{#1}\fi
\par}\nopagebreak[4]
\newcommand*{\dictchar}[1]{\centerline{\LARGE\textbf{#1}}\par}
\pagestyle{fancy}
\fancypagestyle{basicstyle}{%
\fancyhf{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[LE,RO]{\textbf{\chaptitle}}
\fancyhead[LO,RE]{\textbf{\thepage}}}
\fancypagestyle{dictstyle}{%
\fancyhf{}
\fancyhead[LE,LO]{{\fontfamily{phv}\selectfont{\textbf{\rightmark}}}}
\fancyhead[CO,CE]{\thepage}
\fancyhead[RE,RO]{{\fontfamily{phv}\selectfont{\textbf{\leftmark}}}}}
\begin{document}
\pagestyle{dictstyle}
\dictchar{a}
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar{b}
\entry[headwords]{headwords}{translations}
\end{document}
我怎样才能将 \dictchar 值的拇指索引放置到右边奇数和左边偶数边缘?
答案1
我猜你想要的是章节缩略图或缩略图索引。这是一个使用 TikZ 几乎自动的解决方案:
\documentclass{book}
% load TikZ to draw the boxes
\usepackage{tikz}
\usetikzlibrary{calc}
% use scrpage2 or whatever you want to add
% the boxes to the header to make them appear
% on every page
\usepackage{scrpage2}
\pagestyle{scrheadings}
% new counter to hold the current number of the
% letter to determine the vertical position
\newcounter{letternum}
% newcounter to set the number of thumbs fitting vertical
% and setting the height of a boxes
\newcounter{letterdiv}
\setcounter{letterdiv}{4}
% some margin settings
\newlength{\thumbtopmargin}
\setlength{\thumbtopmargin}{2cm}
\newlength{\thumbbottommargin}
\setlength{\thumbbottommargin}{2cm}
% calculate the box height by dividing the page height
\newlength{\thumbheight}
\pgfmathsetlength{\thumbheight}{%
(\paperheight-\thumbtopmargin-\thumbbottommargin)%
/%
\value{letterdiv}
}
% box width
\newlength{\thumbwidth}
\setlength{\thumbwidth}{1cm}
% style the boxes
\tikzset{
thumb/.style={
fill=black!50!red,
text=white,
minimum height=\thumbheight,
text width=\thumbwidth,
outer sep=0pt,
font=\sffamily\bfseries\Huge,
inner xsep=1.5em,
}
}
% create two new commands to make the thumbs
% that makes it easy to use them im different header elements,
% like in the plain and normal page style etc.
\newcommand{\evenpageletterthumb}[1]{%
% see pgfmanual.pdf for more information about this part
\begin{tikzpicture}[remember picture, overlay]
\node [thumb,align=left,anchor=north west,] at ($%
(current page.north west)-%
(0,{\thumbtopmargin+(\value{letternum}-1)*\thumbheight})%
$) {#1};
\end{tikzpicture}
}
\newcommand{\oddpageletterthumb}[1]{%
\begin{tikzpicture}[remember picture, overlay]
\node [thumb,align=right,anchor=north east,] at ($%
(current page.north east)-%
(0,{\thumbtopmargin+(\value{letternum}-1)*\thumbheight})%
$) {#1};
\end{tikzpicture}
}
% create a new command to set a new lettergroup
\newcommand{\lettergroup}[1]{%
% but I recommend to start a new page
\clearpage
% set a title (optional)
{\Huge\bfseries\sffamily #1}\par\bigskip
% check if we reached the last vertical position and reset it
\ifnum\value{letternum}=\value{letterdiv}\relax
\setcounter{letternum}{0}%
\fi
% check if we reached the last vertical position and reset it
\ifnum\value{letternum}=\value{letterdiv}\relax
\setcounter{letternum}{0}%
\fi
\stepcounter{letternum}%
% use one head or foot element to put in the box
% it doesn't matter which you use since the box
% is positioned on the page absolutely
\lohead[\oddpageletterthumb{#1}]{\oddpageletterthumb{#1}}%
\lehead[\evenpageletterthumb{#1}]{\evenpageletterthumb{#1}}%
}
% for some blindtext
\usepackage{lipsum}
\begin{document}
% usage: \lettergroup{<letter>}
% e.g.
\lettergroup{A}
% your text
\lipsum[1]
\lettergroup{B}
\lipsum[1]
\lettergroup{C}
\lipsum[1]
\lettergroup{D}
\lipsum[1]
\lettergroup{E}
\lipsum[1]
\lettergroup{F}
\lipsum[1]
\lettergroup{G}
\lipsum[1]
\end{document}
更新
我进行了更新,现在可以设置在下一个字母组从 to 再次开始之前,边距中应容纳多少个字母缩略图。这对于数量较多的组来说更好,否则框高度会非常小。我将其重命名为,lettersum
以便letterdiv
名称与函数匹配。
计数器letterdiv
用于设置适合页面高度的框数。我4
在示例中将其设置为,以显示其工作原理。如您所见,第五个字母E
再次打印在第一个位置。
答案2
这是使用该软件包的文档版本background
。其理念与 Tobi 的解决方案类似,但隐藏了更多细节。
\documentclass[twocolumn,a4paper]{book}
% set up a counter for the letters and format it
\newcounter{letter}
\renewcommand{\theletter}{\Alph{letter}}
\usepackage{tikz} % the background package loads this, but we add it here to be explicit
\usepackage[top]{background}
\usepackage{calc,ifthen}
\usepackage{lipsum} % for dummy text
\SetBgContents{} % set the background content to nothing
% Now set up the letters for the thumbs on odd and even pages
% we make this a command \beginthumbs so that we can turn it on
% at the right time in the document.
\makeatletter
\newcommand{\beginthumbs}{%
\AddEverypageHook{%
\ifthenelse{\isodd{\thepage}}%
{\SetBgHshift{68} % Horizontal shift of the thumb
% The next command sets the thumb itself. It can be any tikz command
% Note that we use tikz commands to change the text colour not the
% background command \SetBgColor since the text is inside a tikz \node
\SetBgContents{\tikz{\node[fill,red,minimum size=1.4em,inner sep=0,text=black]{\theletter};}}
\SetBgScale{4}
\SetBgVshift{-6*\value{letter}}}% Vertical shift will move down
% Now do the same for the even pages, changing the Hshift sign to -
{\SetBgHshift{-68}
\SetBgContents{\tikz{\node[fill,red,minimum size=1.4 em,inner sep=0,text=black]{\theletter};}}
\SetBgScale{4}
\SetBgVshift{-6*\value{letter}}}%
\bg@material}}
\makeatother
% end of thumbs code
\usepackage[top=1.5cm, bottom=1.5cm, left=2cm, right=2cm]{geometry}
\usepackage{fancyhdr}
\usepackage{hanging}
\usepackage[utf8x, utf8]{inputenc}
\usepackage[T1]{fontenc}
\newcommand\entry[3][]{\hangpara{2em}{1}{\fontfamily{phv}\selectfont{\textbf{{#2}}}}\
#3\ifx\relax#1\relax\markboth{#2}{#2}\else\markboth{#1}{#1}\fi
\par}\nopagebreak[4]
% Instead of specifying the letter directly, we just increment the counter
% this could be wrapped into sectioning code with titlesec to be cleaner
\newcommand*{\dictchar}{\stepcounter{letter}\centerline{\LARGE\textbf{\theletter}}\par}
\pagestyle{fancy}
\fancypagestyle{basicstyle}{%
\fancyhf{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[LE,RO]{\textbf{\chaptitle}}
\fancyhead[LO,RE]{\textbf{\thepage}}}
\fancypagestyle{dictstyle}{%
\fancyhf{}
\fancyhead[LE,LO]{{\fontfamily{phv}\selectfont{\textbf{\rightmark}}}}
\fancyhead[CO,CE]{\thepage}
\fancyhead[RE,RO]{{\fontfamily{phv}\selectfont{\textbf{\leftmark}}}}}
\begin{document}
% now see that the whole thing works
\chapter{A chapter}
\lipsum
\clearpage
\pagestyle{dictstyle}
% now we issue the command to start the thumbs
\beginthumbs
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\clearpage
\dictchar
\entry[headwords]{headwords}{translations}
\end{document}
答案3
以下是Tobi 的方法按照OP 的要求,fancyhdr
使用 而不是scrpage2
(太长,无法发表评论)。我使用了 OP 示例中的页面样式。
请注意,我必须\fancypagestyle
在\newcommand
在(字母组)而不是页面样式章节开始我可以重新定义plain
页面样式,但我想避免可能产生的不良副作用。
如果想要使用makeindex
或xindy
,则必须(重新)创建\lettergroup
标题的样式文件。
\documentclass{book}
% load TikZ to draw the boxes
\usepackage{tikz}
\usetikzlibrary{calc}
% use fancyhdr or whatever you want to add
% the boxes to the header to make them appear
% on every page
\usepackage{fancyhdr}
\fancypagestyle{basicstyle}{%
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhf{}
\fancyhead[LE,RO]{\fontfamily{phv}\selectfont\textbf{\rightmark}}
\fancyhead[LO,RE]{\textbf{\thepage}}
}
% new counter to hold the current number of the
% letter to determine the vertical position
\newcounter{letternum}\fontfamily{phv}\selectfont
% newcounter to set the number of thumbs fitting vertical
% and setting the height of a boxes
\newcounter{letterdiv}
\setcounter{letterdiv}{4}
% some margin settings
\newlength{\thumbtopmargin}
\setlength{\thumbtopmargin}{2cm}
\newlength{\thumbbottommargin}
\setlength{\thumbbottommargin}{2cm}
% calculate the box height by dividing the page height
\newlength{\thumbheight}
\pgfmathsetlength{\thumbheight}{%
(\paperheight-\thumbtopmargin-\thumbbottommargin)%
/%
\value{letterdiv}
}
% box width
\newlength{\thumbwidth}
\setlength{\thumbwidth}{1cm}
% style the boxes
\tikzset{
thumb/.style={
fill=black!50!red,
text=white,
minimum height=\thumbheight,
text width=\thumbwidth,
outer sep=0pt,
font=\sffamily\bfseries\Huge,
inner xsep=1.5em,
}
}
% create two new commands to make the thumbs
% that makes it easy to use them im different header elements,
% like in the plain and normal page style etc.
\newcommand{\evenpageletterthumb}[1]{%
% see pgfmanual.pdf for more information about this part
\begin{tikzpicture}[remember picture, overlay]
\node [thumb,align=left,anchor=north west,] at ($%
(current page.north west)-%
(0,{\thumbtopmargin+(\value{letternum}-1)*\thumbheight})%
$) {#1};
\end{tikzpicture}
}
\newcommand{\oddpageletterthumb}[1]{%
\begin{tikzpicture}[remember picture, overlay]
\node [thumb,align=right,anchor=north east,] at ($%
(current page.north east)-%
(0,{\thumbtopmargin+(\value{letternum}-1)*\thumbheight})%
$) {#1};
\end{tikzpicture}
}
% create a new command to set a new lettergroup
\newcommand{\lettergroup}[1]{%
\fancypagestyle{dictstyle}{%
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhf{}
\fancyhead[LO]{\fontfamily{phv}\selectfont{\textbf{\scshape Letter #1}}}
\fancyhead[C]{\thepage}
\fancyhead[RE]{\fontfamily{phv}\selectfont{\textbf{\scshape Letter #1}}}
\fancyfoot[LE]{\evenpageletterthumb{#1}}
\fancyfoot[RO]{\oddpageletterthumb{#1}}
}
\fancypagestyle{chapterstart}{%
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhf{}
\chead{\oddpageletterthumb{#1}}% chapters start only on odd pages
\cfoot{\thepage}
}
\chapter*{#1}
\thispagestyle{chapterstart}
\pagestyle{dictstyle}
% check if we reached the last vertical position and reset it
\ifnum\value{letternum}=\value{letterdiv}\relax
\setcounter{letternum}{0}%
\fi
% check if we reached the last vertical position and reset it
\ifnum\value{letternum}=\value{letterdiv}\relax
\setcounter{letternum}{0}%
\fi
\stepcounter{letternum}%
% use one head or foot element to put in the box
% it doesn't matter which you use since the box
% is positioned on the page absolutely
}
% for some blindtext
\usepackage{kantlipsum,lipsum}
\begin{document}
\pagestyle{basicstyle}
\chapter*{Pseudo-Kantian blindtext}
\kant[1-5]
% usage: \lettergroup{<letter>}
% e.g.
\lettergroup{A}
% your text
\lipsum[1-15]
\lettergroup{B}
\lipsum[16-30]
\lettergroup{C}
\lipsum[31-45]
\lettergroup{D}
\lipsum[46-60]
\end{document}
答案4
此答案是所有答案的总结,首先是 Toby 的答案,然后是 Speravir 使用 fancyhdr 进行的修改。此解决方案将词典页面中的第一个词条和最后一个词条保留在页眉中,同时在页面边缘垂直设置一个带有当前字母的所谓缩略索引;缩略索引的位置取决于字母的数量。
\documentclass[twocolumn]{book}
\usepackage[top=1.5cm, bottom=1.5cm, left=2cm, right=2cm]{geometry}
\usepackage{fancyhdr}
\usepackage[icelandic, czech, english]{babel}
\usepackage[utf8x, utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hanging}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand\entry[3][]{\hangpara{2em}{1}{\fontfamily{phv}\selectfont{\textbf{{#2}}}}\
#3\ifx\relax#1\relax\markboth{#2}{#2}\else\markboth{#1}{#1}\fi
\par}\nopagebreak[4]
\newcommand*{\dictchar}[1]{\centerline{\LARGE\textbf{#1}}\par}
% use fancyhdr or whatever you want to add
% the boxes to the header to make them appear
% on every page
\pagestyle{fancy}
% new counter to hold the current number of the
% letter to determine the vertical position
\newcounter{letternum}
% newcounter for the sum of all letters to get
% the right height of a box
\newcounter{lettersum}
\setcounter{lettersum}{26}
% some margin settings
\newlength{\thumbtopmargin}
\setlength{\thumbtopmargin}{1cm}
\newlength{\thumbbottommargin}
\setlength{\thumbbottommargin}{3cm}
% calculate the box height by dividing the page height
\newlength{\thumbheight}
\pgfmathsetlength{\thumbheight}{%
(\paperheight-\thumbtopmargin-\thumbbottommargin)%
/%
\value{lettersum}
}
% box width
\newlength{\thumbwidth}
\setlength{\thumbwidth}{1.5cm}
% style the boxes
\tikzset{
thumb/.style={
fill=black!50!red,
text=white,
minimum height=\thumbheight,
text width=\thumbwidth,
outer sep=0pt,
font=\sffamily\bfseries,
}
}
\newcommand{\oddthumb}[1]{%
% see pgfmanual.pdf for more information about this part
\begin{tikzpicture}[remember picture, overlay]
\node [thumb,text centered,anchor=north east,] at ($%
(current page.north east)-%
(0,\thumbtopmargin+\value{letternum}*\thumbheight)%
$) {#1};
\end{tikzpicture}
}
\newcommand{\eventhumb}[1]{%
% see pgfmanual.pdf for more information about this part
\begin{tikzpicture}[remember picture, overlay]
\node [thumb,text centered,anchor=north west,] at ($%
(current page.north west)-%
(0,\thumbtopmargin+\value{letternum}*\thumbheight)%
$) {#1};
\end{tikzpicture}
}
% create a new command to set a new lettergroup
\newcommand{\lettergroup}[1]{%
\fancypagestyle{chapterstart}{%
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\chead{\oddthumb{#1}}% chapters start only on odd pages
\cfoot{\thepage}
}
\fancyhead[LO]{\fontfamily{phv}\selectfont{\textbf{\rightmark}}\oddthumb{#1}}%
\fancyhead[RE]{\fontfamily{phv}\selectfont{\textbf{\leftmark}}\eventhumb{#1}}%
% step the counter of the letters
\stepcounter{letternum}%
}
\fancypagestyle{basicstyle}{%
\fancyhf{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[LE,RO]{\textbf{\chaptitle}}
\fancyhead[LO,RE]{\textbf{\thepage}}}
\fancypagestyle{dictstyle}{%
\renewcommand{\headrulewidth}{0.4pt}
\fancyhf{}
\fancyhead[LE,LO]{{\fontfamily{phv}\selectfont{\textbf{\rightmark}}}}
\fancyhead[CO,CE]{\thepage}
\fancyhead[RE,RO]{{\fontfamily{phv}\selectfont{\textbf{\leftmark}}}}}
\setlength{\columnsep}{20pt}
\setlength{\columnseprule}{0.1pt}
\begin{document}
\pagestyle{dictstyle}
\lettergroup{A}
\dictchar{A}
\entry[headwords]{headwords}{translations}
\entry[headwords2]{headwords2}{translations2}
\clearpage
\lettergroup{B}
\dictchar{B}
\entry[headwords]{headwords}{translations}
\entry[headwords2]{headwords2}{translations2}
\clearpage
\lettergroup{C}
\dictchar{C}
\entry[headwords]{headwords}{translations}
\entry[headwords2]{headwords2}{translations2}
\clearpage
\end{document}