如何自動計算頁面節點內的 tikz 移位

如何自動計算頁面節點內的 tikz 移位

我正在嘗試正確對齊tikzpicture我放在頁腳中的箭頭內的由文字組成的內容。我的問題是我希望箭頭尖端與頁腳的東邊對齊我希望文字的基線與頁腳其他部分中的其餘文字對齊。

似乎沒有一個錨定選項能產生我想要的結果。如果我使用base east錨點,文字會正確對齊,但箭頭會伸出到邊距中,如下所示:

有錨=基地東

我知道如何添加手動班次。在下面的 MWE 中,我有一個或多或少可行的解決方案,透過使用yshift將箭頭拉到正確的位置,但該值是我透過觀察它來確定的。該解決方案如下所示:

在此輸入影像描述

然而,它顯然只適用於此尺寸。有沒有辦法tikz自動計算班次?

這是我的 MWE:

\documentclass{memoir}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{positioning,calc,shapes.arrows}
\usepackage{showframe}
\usepackage{lipsum}

\renewcommand*{\ShowFrameColor}{\color{red}}

% This version correctly aligns the CONTINUE text to the baseline,
% but the arrow head sticks out into the margin.
\newcommand{\ContinueNotice}{%
    \begin{tikzpicture}[remember picture,overlay, font={\large\sffamily\bfseries}]
        \node[single arrow,single arrow head extend=3pt,fill=black,text=white,anchor=base east]
        at (current page footer area.south east) {\enspace CONTINUE\enspace};
\end{tikzpicture}%
}

% This version is more or less correctly aligned, but the yshift is done by eye.
\newcommand{\ContinueNoticeAlt}{%
    \begin{tikzpicture}[remember picture,overlay, font={\large\sffamily\bfseries}]
        \node[single arrow,single arrow head extend=3pt,fill=black,text=white,anchor=east,yshift=-2pt]
        at (current page footer area.east) {\enspace CONTINUE\enspace};
\end{tikzpicture}%
}

\makepagestyle{TestStyle}
\makeoddfoot{TestStyle}{\footnotesize Some Notice}{\thepage}{\ContinueNotice}
\makeevenfoot{TestStyle}{\footnotesize Some Notice}{\thepage}{\ContinueNoticeAlt}
\pagestyle{TestStyle}

\begin{document}

\lipsum

\end{document} 

答案1

使用anchor=eastleft作為節點。用例如 命名節點n並用作 的baseline=(n.base)選項tikzpicture

\documentclass{memoir}
\usepackage{tikzpagenodes}
\usetikzlibrary{shapes.arrows}
\usepackage{showframe}
\usepackage{lipsum}

\renewcommand*{\ShowFrameColor}{\color{red}}

\newcommand{\ContinueNotice}{%
    \begin{tikzpicture}[remember picture,overlay, font={\large\sffamily\bfseries},baseline=(n.base)]
        \node[single arrow,single arrow head extend=3pt,fill=black,text=white,left](n)
        at (current page footer area.south east) {\enspace CONTINUE\enspace};
\end{tikzpicture}%
}

\newcommand{\ContinueNoticeAlt}{%
    \begin{tikzpicture}[remember picture,overlay, font={\large\sffamily\bfseries},baseline=(n.base)]
        \node[single arrow,single arrow head extend=3pt,fill=black,text=white,anchor=east](n)
        at (current page footer area.east) {\enspace CONTINUE\enspace};
\end{tikzpicture}%
}

\makepagestyle{TestStyle}
\makeoddfoot{TestStyle}{\footnotesize Some Notice}{\thepage}{\ContinueNotice}
\makeevenfoot{TestStyle}{\footnotesize Some Notice}{\thepage}{\ContinueNoticeAlt}
\pagestyle{TestStyle}

\begin{document}
\lipsum
\end{document}

在此輸入影像描述


更新

請注意,無需使用tikzpagenodesremember picture。然後你只需運行一次。

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows}
\usepackage{showframe}
\usepackage{lipsum}

\renewcommand*{\ShowFrameColor}{\color{red}}

\newcommand{\ContinueNotice}{%
  \begin{tikzpicture}[overlay, font={\large\sffamily\bfseries},baseline=(n.base)]
    \node[single arrow,single arrow head extend=3pt,fill=black,text=white,left](n)
      {\enspace CONTINUE\enspace};
  \end{tikzpicture}%
}

\newcommand{\ContinueNoticeAlt}{%
  \begin{tikzpicture}[overlay, font={\large\sffamily\bfseries},baseline=(n.base)]
    \node[single arrow,single arrow head extend=3pt,fill=black,text=white,anchor=east](n)
      {\enspace CONTINUE\enspace};
  \end{tikzpicture}%
}

\makepagestyle{TestStyle}
\makeoddfoot{TestStyle}{\footnotesize Some Notice}{\thepage}{\ContinueNotice}
\makeevenfoot{TestStyle}{\footnotesize Some Notice}{\thepage}{\ContinueNoticeAlt}
\pagestyle{TestStyle}

\begin{document}
\lipsum
\end{document}

結果與上面相同。

相關內容