術語表和索引頁的自訂邊框

術語表和索引頁的自訂邊框

我正在使用 Latex 準備一本技術書科馬腳本 srcbook類,我想僅向術語表和索引頁添加灰色邊框。我們的想法是讓它們在合上書後很容易找到,如下例所示:

索引頁

我見過使用fancyhdror 的類似解決方案tikz,但是(1)我不知道它們是否可以直接應用而無需擰緊 KOMA,(2)我發現沒有辦法將邊框僅限於索引/詞彙表頁面,我當然,必須有一種明顯的方法來完成這兩件事。

更新:我找到了一個解決方案(見下文),使用eso-picifthen套件來繪製邊框和etoolbox修補theindex環境並控制它出現的位置。

答案1

您可以將該套件background與 TikZ 和定義的節點結合使用current page

\documentclass{scrbook}
\usepackage[]{background}
\backgroundsetup{contents={}}
\usepackage{lipsum}
\usepackage{imakeidx}

\makeindex
\begin{document}
\index{a}\lipsum[1-10]

\AddEverypageHook{%
   \tikz[remember picture,overlay]\draw[line width=1cm](current page.north east) rectangle (current page.south east);%
}
\printindex
\end{document}

答案2

我正在回答我自己的問題,希望以後有人會發現它有用。

我的解決方案受到啟發並基於這個答案因為使用 Tikz 顯示了該類別的一些奇怪行為scrbook(至少在我的系統中)。我建立了兩個新命令\addthumbindex\clearthumbindex可分別用於啟用和停用拇指索引。第一個指令接收拇指索引的顏色和寬度作為強制參數,如果您需要在 A4 中列印但希望將其裁切為 B5,您也可以指定一個可選bleed參數(下面的 MWE 顯示了一個範例)。

不過這個解決方案並不完美:如下圖所示,我無法在實際索引開始之前刪除頁面中的邊框,所以我仍在尋找解決方案(無論是對我的或完全不同的方法)。編輯:已修復。

\documentclass[b5paper]{scrbook}
\usepackage[a4,cam,center]{crop} % to show cropping marks (if needed)
\usepackage{xcolor}              % to have colors 
\usepackage{eso-pic}             % put things into background 
\usepackage{ifthen}              % support for conditionals
\usepackage{imakeidx}            % to create the index

\usepackage{lipsum}              % for sample text

\definecolor{thumbindexgray}{RGB}{102,102,102}

% patch `begin{theindex}` to add the border
\AtBeginEnvironment{theindex}{\addthumbindex[bleed]{.5cm}{thumbindexgray}}

% patch `end{theindex}` to clear the border
\AtEndEnvironment{theindex}{\clearthumbindex}

\newcommand{\addthumbindex}[3][]{
    \newlength{\thumbindexwidth}
    \setlength{\thumbindexwidth}{#2}

    \ifthenelse{\equal{#1}{bleed}}{
        %\clearpage (not needed if we patch 'theindex' environment)
        \AddToShipoutPicture{% from package eso-pic: put something to the background
            \ifthenelse{\isodd{\thepage}}{
                % odd page: right bar
                \AtPageLowerLeft{% start the bar at the bottom right of the page
                    \put(\LenToUnit{\dimexpr\paperwidth+\thumbindexwidth-2\thumbindexwidth},
                         \LenToUnit{\dimexpr-\thumbindexwidth}){% move it to the top right
                        \color{#3}\rule{2\thumbindexwidth}{\LenToUnit{\dimexpr\paperheight+2\thumbindexwidth}}%
                    }%
                }%
            }%
            {%
                % even page: left bar
                \AtPageLowerLeft{% start the bar at the left bottom of the page
                    \put(\LenToUnit{\dimexpr\thumbindexwidth-2\thumbindexwidth},
                         \LenToUnit{\dimexpr-\thumbindexwidth}){% move it to the top right
                        \color{#3}\rule{2\thumbindexwidth}{\LenToUnit{\dimexpr\paperheight+2\thumbindexwidth}}%
                    }%
                    %\color{#3}\rule{\thumbindexwidth}{\LenToUnit\paperheight}%
                }%
            }%
        }
    }
    {
        %\clearpage (not needed if we patch 'theindex' environment)            
        \AddToShipoutPicture{% from package eso-pic: put something to the background
            \ifthenelse{\isodd{\thepage}}{
                % odd page: right bar
                \AtPageLowerLeft{% start the bar at the bottom right of the page
                    \put(\LenToUnit{\dimexpr\paperwidth-\thumbindexwidth},0){% move it to the top right
                        \color{#3}\rule{\thumbindexwidth}{\LenToUnit\paperheight}%
                    }%
                }%
            }%
            {%
                % even page: left bar
                \AtPageLowerLeft{% start the bar at the left bottom of the page
                    \color{#3}\rule{\thumbindexwidth}{\LenToUnit\paperheight}%
                }%
            }%
        }
    }
}

\newcommand{\clearthumbindex}{
    \clearpage
    \ClearShipoutPicture
}

\makeindex

\begin{document}

\input{fake_index.tex} % just a collection of \index{XXX}\lipsum[1-10]

% \addthumbindex[bleed]{.5cm}{thumbindexgray} % (not needed if patching 'theindex')
\printindex
% \clearthumbindex{}  % (not needed if patching 'theindex')

\end{document}

編輯:我透過修補使用套件theindex產生的環境找到了解決方案。為了將來的參考,該代碼可以在和 中工作,並且我假設類似的東西可以與術語表或首字母縮略詞列表一起使用。我已對上面的程式碼添加了更改,並在下面添加了最終結果的圖片。makeindexetoolboxpdflatexxelatex

最後結果

相關內容