如何让带有文本的 tikz 框变得更长?

如何让带有文本的 tikz 框变得更长?

我想让tikz带有字母(拇指索引)的盒子更长(将其拉伸到裁剪边缘),但我需要保持字母的位置和盒子的位置不变。

可以创建原始框在这个答案中找到。

更新:包括正在工作的 MWE。下面的 MWE 说明了 A4 纸张大小、C5 布局。目前拇指索引固定在纸张边缘,因此它位于打印区域之外(C5)。我需要将拇指放在原始位置(在打印区域的边缘),同时确保字母正确定位并且拇指索引延伸到边缘。拇指的原始宽度为 0.5 厘米,字母位于内部中央。

在此处输入图片描述

\documentclass[8pt, a4paper, twoside, openright]{extbook}
\usepackage{geometry}
\geometry
{ headsep    =   \baselineskip
, textwidth  = 42\baselineskip
, textheight = 60\baselineskip
, hmarginratio = 2:3
, vmarginratio = 2:3
, bindingoffset = 0cm
, onecolumn
, layout=c5paper,
, layouthoffset=\dimexpr(\paperwidth-\csname Gm@layoutwidth\endcsname)/2\relax
, layoutvoffset = 2cm
, showcrop
}

\usepackage[icelandic, latin, czech]{babel}
\usepackage{csquotes}
\usepackage{lipsum}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tgpagella}
\usepackage[scaled=0.88]{helvet}      % relative scale of the two fonts
\def\phvfamily{\fontfamily{phv}\selectfont}

% \normalsize should be {8pt}{9.6pt}
\def\HUGE {\fontsize{23.887872pt}{3\baselineskip}\selectfont}
\def\Huge {\fontsize{19.906560pt}{3\baselineskip}\selectfont}
\def\huge {\fontsize{16.588800pt}{3\baselineskip}\selectfont}
\def\LARGE{\fontsize{13.824000pt}{2\baselineskip}\selectfont}
\def\Large{\fontsize{11.520000pt}{2\baselineskip}\selectfont}
\def\large{\fontsize{ 9.600000pt}{2\baselineskip}\selectfont}

% Two columns layout ruler
\setlength\columnsep    {2\baselineskip}
\setlength\columnseprule{0.4pt}

% Necessary for baseline alignment
\topskip=\baselineskip
\raggedbottom
\setlength\parskip{0pt} % it's better to avoid glue


% ######################################################### ASSORTED PACKAGES #

\usepackage{tikz}
\usetikzlibrary{calc}

% ############################################################ BASELINE GRID #

\usepackage{eso-pic}
\usepackage{tikzpagenodes}

% Command to draw a baseline grid
\newcommand\drawbaselinegrid{%
  \begin{tikzpicture}[overlay,remember picture]
    \draw [red!30!white, ultra thin, dashed]
      (0,0) grid [ ystep  = \baselineskip, xstep = \textwidth
                 , shift  = (current page text area.north west)
                 , yshift = -\dp\strutbox
                 ] ++(\textwidth,-\textheight);
    \draw [red!30!white, thin]
      (0,0) grid [ step = \baselineskip, xstep = \textwidth
                 , shift=(current page text area.north)
                 ] ++(0.5\textwidth,-\textheight)
      (0,0) grid [ step = \baselineskip, xstep = \textwidth
                 , shift=(current page text area.north)
                 ] ++(-0.5\textwidth,-\textheight);
    \draw[black!10!white]
      (current page text area.north west)
        rectangle (current page text area.south east);
  \end{tikzpicture}}

% Draw a baseline grid on every page
\AddToShipoutPicture{\drawbaselinegrid}


% ############################################################### PAGE STYLES #

\usepackage{fancyhdr}

% -------------------------------------- BASIC PAGE STYLE
\fancypagestyle{plain}{
  \fancyhf\relax                       % Clear header/footer
  \renewcommand \headrulewidth {0.0pt} % No header rule
  \renewcommand \footrulewidth {0.0pt} % No footer rule
  \fancyfoot[C]{\thepage}              % Page number in footer, centred
}

% -------------------------------------- DICTIONARY PAGE STYLE
\fancypagestyle{myheadings}{
  \fancyhf\relax                       % Clear header/footer
  \renewcommand \headrulewidth {0.4pt} % Thin header rule
  \fancyhead[CO,CE]{\thepage}          % Page number in header, centred
  % NOTE: the page numbers will be printed when the dictionary is ready
  \fancyhead[LE,LO]{\phvfamily\bfseries\rightmark}
  \fancyhead[RE,RO]{\phvfamily\bfseries\leftmark}
}

\pagestyle{plain}  

% #################################################################### COLORS #

\usepackage{color}
\definecolor {darkgreen}          {rgb} {0.40, 0.01, 0.24}

% COLORS FOR THUMB INDEXES
\definecolor {color1}             {RGB} { 182,   86,    0}
\definecolor {color2}             {RGB} { 143,    9,    6}
\definecolor {color3}             {RGB} {   3,   23,  118}
\definecolor {color4}             {RGB} {   0,   82,  168}
\definecolor {color5}             {RGB} {   0,   85,  142}

% ############################################################# THUMB INDEXES #

\newcommand\BoxColor[1]{%
\ifcase#1 darkgreen!30\or color1\or color2\or color3\or color4\or color5\fi}

% THUMB INDEXES
% 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}{34}
% some margin settings
\newlength{\thumbtopmargin}
\setlength{\thumbtopmargin}{3cm} %1cm
\newlength{\thumbbottommargin}
\setlength{\thumbbottommargin}{6cm} %2.5cm
% calculate the box height by dividing the page height
\newlength{\thumbheight}
\pgfmathsetlength{\thumbheight}{%
(\paperheight-\thumbtopmargin-\thumbbottommargin)%
/%
\value{lettersum}
}
% box width
\newlength{\thumbwidth}
\setlength{\thumbwidth}{2cm} %0.5cm
% style the boxes
\tikzset{
thumb/.style={
   text=white,
   minimum height=\thumbheight,
   text width=\thumbwidth,
   outer sep=0pt,
   font=\sffamily\bfseries,
 }
 }

\def\thumbnew{}
\def\thumbold{}
\usepackage{everypage}
\AddEverypageHook{\if\relax\thumbnew\relax\xdef\thumbnew{\thumbold}\fi}

\def\ethumbs#1,#2\relax{\if\relax#1\relax\else\eventhumb{#1}\fi%
                        \if\relax#2\relax\else\ethumbs#2\relax\fi%
                        \gdef\thumbnew{}%
                        \gdef\thumbold{#1,}%
}

\def\othumbs#1,#2\relax{\if\relax#1\relax\else\oddthumb{#1}\fi%
                        \if\relax#2\relax\else\othumbs#2\relax\fi%
                        \gdef\thumbold{#1,}%
                        \gdef\thumbnew{}%
}

\newcommand{\drawthumb}[2]{%
  % see pgfmanual.pdf for more information about this part
  \begin{tikzpicture}[remember picture, overlay]
    \node [thumb, fill=\BoxColor{#1}, text centered, anchor=north #2]
       at ($(current page.north #2)-%
%            (0,\thumbtopmargin+\value{letternum}*\thumbheight)%
            (0,\thumbtopmargin+#1*\thumbheight)$) {\csname Let#1\endcsname};
   \end{tikzpicture}}

% I had to exchange the east/west anchors of the thumbs
% because they were being drawn flipped. I don't know why.
\newcommand{\oddthumb} [1]{\drawthumb{#1}{west}}
\newcommand{\eventhumb}[1]{\drawthumb{#1}{east}}

% create a new command to set a new lettergroup with thumb indexes
\newcommand{\lettergroup}[1]{%
  % step the counter of the letters
  \refstepcounter{letternum}%
  \expandafter\gdef\csname Let\theletternum\endcsname{#1}%
  \xdef\thumbnew{\theletternum,\thumbnew}%
  \fancyhead[LO]{\phvfamily\bfseries\rightmark%
    \expandafter\ethumbs\thumbnew\relax\relax\relax}%
  \fancyhead[RE]{\phvfamily\bfseries\leftmark%
    \expandafter\othumbs\thumbnew\relax\relax\relax}%
}

% #################################################### ASSORTED CUSTOM MACROS #

\def\textIS#1{\foreignlanguage{icelandic}{#1}}
\def\textCS#1{\foreignlanguage{czech}{#1}}
\def\textLA#1{\foreignlanguage{latin}{#1}}

\usepackage{pgffor}

\newcommand\blspace[1][1]{\vspace{#1\baselineskip}}

\usepackage{placeins}

\newcommand*{\dicLetter}[2]{%
  \FloatBarrier\newpage\phantomsection\pdfbookmark[1]{#1}{#2}%
  \noindent\parbox[b][9\baselineskip][c]{\columnwidth}
    {\centering\HUGE\strut\smash{\MakeUppercase{#1}~\MakeLowercase{#1}}}%
      %\par\xdef\tpd{\the\prevdepth}
      %\par\prevdepth\tpd%
  \expandafter\lettergroup{\MakeLowercase{#1}}}

% ###################################################### HYPERREF & PDF INFO #
\usepackage[pdftex, unicode, hyperfootnotes=false]{hyperref}

\begin{document}
\dicLetter{a}{letter1}
\lipsum[1-2]
\clearpage
\dicLetter{b}{letter2}
\lipsum[1-2]
\clearpage
\dicLetter{c}{letter3}
\lipsum[1-2]
\clearpage
\dicLetter{d}{letter4}
\lipsum[1-2]
\clearpage
\dicLetter{e}{letter5}
\lipsum[1-2]
\end{document}

答案1

Paulo Brasolin 解决了这个问题。我重新发布了正确答案。希望它以后能帮助到其他用户。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcounter{letternum}
\newcounter{lettersum}                 \setcounter{lettersum}{34}
% these margins separate top thumb from top of page and last thumb from
% bottom of page. BEWARE, it's from top of the (cut out) page, not the folio!
\newlength{\thumbtopmargin}            \setlength{\thumbtopmargin}{1cm}
\newlength{\thumbbottommargin}         \setlength{\thumbbottommargin}{1cm}
\newlength{\thumbwidth}                \setlength{\thumbwidth}{2.20cm}
\newlength{\thumbheight}
\pgfmathsetlength{\thumbheight}%
  {(\csname Gm@layoutheight\endcsname-\thumbtopmargin-\thumbbottommargin)/\value{lettersum}}
% inner xsep of letter from box margin
\newlength{\thumbsep}                  \setlength{\thumbsep}{.30cm}
% overlap over cutting line
\newlength{\thumboverlap}              \setlength{\thumboverlap}{3cm}

\tikzset{
  thumb/.style={
    text=white,
    outer sep=0pt,
    inner xsep=\thumbsep,
    minimum height=\thumbheight,
    text width=\thumbwidth-2\thumbsep,
    font=\sffamily\bfseries,},
  thumb east/.style={thumb,
    xshift=\dimexpr(+\thumboverlap-\paperwidth+\csname Gm@layoutwidth\endcsname)/2\relax,
    align=left,anchor=north east,},
  thumb west/.style={thumb,
    xshift=\dimexpr(-\thumboverlap+\paperwidth-\csname Gm@layoutwidth\endcsname)/2\relax,
    align=right,anchor=north west,},
}

\def\thumbnew{}
\def\thumbold{}
\usepackage{everypage}
\AddEverypageHook{\if\relax\thumbnew\relax\xdef\thumbnew{\thumbold}\fi}

\def\ethumbs#1,#2\relax%
  {\if\relax#1\relax\else\eventhumb{#1}\fi%
   \if\relax#2\relax\else\ethumbs#2\relax\fi%
   \gdef\thumbnew{}%
   \gdef\thumbold{#1,}}

\def\othumbs#1,#2\relax%
  {\if\relax#1\relax\else\oddthumb{#1}\fi%
   \if\relax#2\relax\else\othumbs#2\relax\fi%
   \gdef\thumbold{#1,}%
   \gdef\thumbnew{}}

\newcommand{\drawthumb}[2]{%
  \begin{tikzpicture}[remember picture, overlay]
    \node [thumb #2, fill=\BoxColor{#1}]
       at ($(current page.north #2)-%
            (0,\csname Gm@layoutvoffset\endcsname+\thumbtopmargin-\thumbheight+%
               #1*\thumbheight)$) {\csname Let#1\endcsname};
   \end{tikzpicture}}

\newcommand{\oddthumb} [1]{\drawthumb{#1}{west}}
\newcommand{\eventhumb}[1]{\drawthumb{#1}{east}}

\newcommand{\lettergroup}[1]%
  {\refstepcounter{letternum}%
   \expandafter\gdef\csname Let\theletternum\endcsname{#1}%
   \xdef\thumbnew{\theletternum,\thumbnew}%
   \fancyhead[LO]{\phvfamily\bfseries\rightmark%
     \expandafter\ethumbs\thumbnew\relax\relax\relax}%
   \fancyhead[RE]{\phvfamily\bfseries\leftmark%
     \expandafter\othumbs\thumbnew\relax\relax\relax}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

相关内容