第三版

第三版

我想为我的简历定义一种特殊的分段类型。但我遇到了一个自己无法解决的问题。我得到了以下代码,它生成了我想要的带有颜色渐变的分段标题。将它用于第一节效果很好,但对于后续部分,我得到的结果总是与第一节中写的结果相同。以下代码将说明该问题:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns,positioning,fit}
\tikzset{
  zero sep/.style = {inner sep=0pt, outer sep=0pt},
}
\begin{document}
  \newsavebox{\tempbox}
  \newcommand\tikzsection[1]{%
    \begin{tikzfadingfrompicture}[name=tikzsection]
      \node [minimum width=50mm, minimum height=2.5mm, fill=white, zero sep] (box node) {};
      \node (text node) [text=white, right=10pt of box node.east, anchor=west,  zero sep] {\normalfont \Large \bfseries #1};
      \node [fit=(box node.north west) (text node.south east) (text node.north west) (box node.south east)] {};
    \end{tikzfadingfrompicture}
    \begin{lrbox}{\tempbox}%
      \begin{tikzpicture}
        \node [text width=50mm, minimum height=2.5mm, fill=white, zero sep] (boxnode) {};
        \node [text=white, right=10pt of boxnode.east, anchor=west,  zero sep] (textnode) {\normalfont \Large \bfseries #1};
        \node (fitnode) [fit=(boxnode.north west) (textnode.south east) (textnode.north west) (boxnode.south east)] {};
        \shade[path fading=tikzsection, fit fading=false,left color=blue, right color=black]
        (fitnode.north west) rectangle (fitnode.south east);
      \end{tikzpicture}%
    \end{lrbox}
    % Now we use the fading in another picture:
    \section{\usebox\tempbox{}}%
  }

  \tikzsection{First section}
  Some text
  \tikzsection{Secoooooond section}
  Some text
\tikzsection{Short}
  Some text


\end{document}

有人能帮我找出这里出了什么问题吗?为什么标题为“第二部分”的部分被渲染为“第一部分”?

3 个部分

\listfiles给出以下列表:

  • article.cls 2007/10/19 v1.4h 标准 LaTeX 文档类
  • size10.clo 2007/10/19 v1.4h 标准 LaTeX 文件(尺寸选项)
  • tikz.sty 2013/12/13 v3.0.0(rcs-修订版 1.142)
  • pgf.sty 2013/12/18 v3.0.0(rcs-修订版 1.14)
  • pgfrcs.sty 2013/12/20 v3.0.0 (rcs-修订版 1.28)
  • everyshi.sty 2001/05/15 v3.00 EveryShipout 包 (MS)
  • pgfrcs.code.tex pgfcore.sty 2010/04/11 v3.0.0 (rcs-修订版 1.7)
  • graphicx.sty 1999/02/16 v1.0f 增强型 LaTeX 图形 (DPC、SPQR)
  • keyval.sty 1999/03/16 v1.13 键=值解析器(DPC)
  • graphics.sty 2009/02/05 v1.0o 标准 LaTeX 图形 (DPC,SPQR)
  • trig.sty 1999/03/16 v1.09 正弦余弦正切 (DPC)
  • graphics.cfg 2010/04/23 v1.9 TeX Live 的图形配置
  • xetex.def 2013/04/29 v0.96 LaTeX 颜色/图形驱动程序,适用于 XeTeX (RRM/JK)
  • pgfsys.sty 2013/11/30 v3.0.0(rcs-修订版 1.47)
  • pgfsyssoftpath.code.tex 2013/09/09(rcs-修订版 1.9)
  • pgfsysprotocol.code.tex 2006/10/16 (rcs-修订版 1.4)
  • xcolor.sty 2007/01/21 v2.11 LaTeX 颜色扩展
  • color.cfg 2007/01/18 v1.5 teTeX/TeXLive 的颜色配置
  • pgfcomp-version-0-65.sty 2007/07/03 v3.0.0 (rcs-修订版 1.7)
  • pgfcomp-version-1-18.sty 2007/07/23 v3.0.0 (rcs-修订版 1.1)
  • pgffor.sty 2013/12/13 v3.0.0 (rcs-修订版 1.25)

答案1

解决方法对于 XeLaTeX :每个使用不同的名称tikzfadingfrompicture

第三版

(与 XeLaTeX 配合使用,具有与第二版相同的功能。)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns,positioning,fit,calc}
\tikzset{
  zero sep/.style = {inner sep=0pt, outer sep=0pt},
}

\newcommand\tikzsection[1]{%
  \pgfmathsetmacro\randref{rand}
  \begin{tikzfadingfrompicture}[name=tikzsection \randref]
    \node[fill=white,anchor=south east,zero sep,minimum width=5cm,minimum height=2.5mm] (box node){};
    \node [text=white,anchor=base west,text depth=5pt,text height=12pt,zero sep,
    font=\normalfont\Large\bfseries,right=10pt of box node,
    text width=5.9cm,align=left] (text node) {#1};
    \node [fit={(box node)(text node)
      },zero sep] (myfit) {};
    \path let \p1=(myfit.south west), \p2=(myfit.north east), \n1={\x2-\x1}, \n2={\y2-\y1} in
    \pgfextra{\xdef\lenx{\n1} \xdef\leny{\n2}};
  \end{tikzfadingfrompicture}
  \section[#1]{%
    \begin{tikzpicture}[baseline=.5*5pt-.5*12pt]
      \path[path fading=tikzsection \randref, fit fading=false,left color=blue, right color=black]
      (-.5*\lenx,-.5*\leny) rectangle ++(\lenx,\leny);
    \end{tikzpicture}
  }
}
\pagestyle{empty}

\begin{document}
\tikzsection{First section}
Some text
\tikzsection{Secoooooond segtion}
Some text
\tikzsection{Short}
Some text

\end{document}

第二版

这是一个新版本:

  • 使用正确的 tikz 褪色位置,
  • 没有保存框,
  • 关心标题的深度和高度,
  • 正确对齐基线,
  • 标题(和褪色)的长度固定(15厘米)。

在此处输入图片描述

\documentclass{article}
\usepackage[rgb]{xcolor}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns,positioning,fit,calc}
\tikzset{
  zero sep/.style = {inner sep=0pt, outer sep=0pt},
}

\newcommand\tikzsection[1]{%
  \pgfmathsetmacro\randref{rand}
  \begin{tikzfadingfrompicture}[name=tikzsection \randref]
    \fill[white] (0,0) rectangle +(5cm,2.5mm);
    \node [text=white,anchor=base west,text depth=5pt,text height=12pt,zero sep,font=\normalfont\Large\bfseries,
    text width=10cm,align=left]
    (text node) at (5cm+10pt,0) {#1};
    \node [fit={(0,0)(text node)},zero sep] (myfit) {};
    \path let \p1=(myfit.south west), \p2=(myfit.north east), \n1={\x2-\x1}, \n2={\y2-\y1} in
    \pgfextra{\xdef\lenx{\n1} \xdef\leny{\n2}};
  \end{tikzfadingfrompicture}
  \typeout{lenx:\lenx}
  \typeout{leny:\leny}
  \section[#1]{%
    \begin{tikzpicture}[baseline=.5*5pt-.5*12pt]
      \path[path fading=tikzsection \randref, fit fading=false,left color=blue, right color=black]
      (-.5*\lenx,-.5*\leny) rectangle ++(\lenx,\leny);
    \end{tikzpicture}
  }
}

\begin{document}
\tikzsection{First section}
Some text
\tikzsection{Secoooooond segtion}
Some text
\tikzsection{Short}
Some text

\end{document}

第一个版本

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns,positioning,fit}
\tikzset{
  zero sep/.style = {inner sep=0pt, outer sep=0pt},
}
\begin{document}


  \newsavebox{\tempbox}
  \newcommand\tikzsection[1]{%
    \begin{tikzfadingfrompicture}[name=tikzsection #1]
      \node [minimum width=50mm, minimum height=2.5mm, fill=white, zero sep] (box node) {};
      \node (text node) [text=white, right=10pt of box node.east, anchor=west,  zero sep] {\normalfont \Large \bfseries #1};
      \node [fit=(box node.north west) (text node.south east) (text node.north west) (box node.south east)] {};
    \end{tikzfadingfrompicture}
    \begin{lrbox}{\tempbox}%
      \begin{tikzpicture}
        \node [text width=50mm, minimum height=2.5mm, fill=white, zero sep] (boxnode) {};
        \node [text=white, right=10pt of boxnode.east, anchor=west,  zero sep] (textnode) {\normalfont \Large \bfseries #1};
        \node (fitnode) [fit=(boxnode.north west) (textnode.south east) (textnode.north west) (boxnode.south east)] {};
        \shade[path fading=tikzsection #1, fit fading=false,left color=blue, right color=black]
        (fitnode.north west) rectangle (fitnode.south east);
      \end{tikzpicture}%
    \end{lrbox}
    % Now we use the fading in another picture:
    \section[#1]{\usebox\tempbox{}}%
  }

  \tikzsection{First section}
  Some text
  \tikzsection{Secoooooond section}
  Some text
\tikzsection{Short}
  Some text


\end{document}

相关内容