TikZ&Titlesec:复杂零件设计

TikZ&Titlesec:复杂零件设计

我正在尝试进行如下图所示的设计。

在此处输入图片描述

背景包含两层:垂直线条图案和渐变层,下层颜色为透明,上层颜色为白色垂直线条。

第一个问题:如何把文字放入彩盒中?这个问题与titlesec包装有关。

在此处输入图片描述

第二个问题是图层管理:如何放置对象模式库下方的淡入淡出矩形和上方的部件标签?如您所见,此问题也与 TikZ 包有关。

MVE 是...

\documentclass[a4paper,twoside]{article}

\usepackage[svgnames,x11names]{xcolor}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns,backgrounds}

\usepackage{titletoc}
\usepackage[toctitles,pagestyles]{titlesec}

\usepackage{multicol}

\oddsidemargin=-10.4mm
\evensidemargin=-20.4mm
\topmargin=-22mm
\textwidth=190mm
\textheight=275mm
\headheight = 5mm
\headsep = 2mm
\footskip = 7mm

\titleformat{\part}[block]{\Large\sffamily}
  {\filright\Huge\sffamily\bfseries \hspace*{2mm}%
  \begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
    \node[fill=DarkGoldenrod1,rectangle,rounded corners,text=white] {Part \thepart};
    \fill [Gold2,path fading=north] (-2,-1) rectangle (\columnwidth-22mm,1.5);
  \end{tikzpicture}}
  {1ex}
  {}
  []

\begin{document}
\part{The trends in art in XX}

\newpage\twocolumn
\part{The World Wars influence}

\newpage\onecolumn
\begin{multicols}{2}
\part{The IT influence}
\end{multicols}

\end{document} 

答案1

您可以将explicit选项传递给titlesec并将标题指定为#1。以下内容可作为您进一步完善和改进的起点。

\documentclass[a4paper,twoside]{article}

\usepackage[svgnames,x11names]{xcolor}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns,backgrounds,fit}

\usepackage{titletoc}
\usepackage[toctitles,pagestyles,explicit]{titlesec}

\usepackage{multicol}

\oddsidemargin=-10.4mm
\evensidemargin=-20.4mm
\topmargin=-22mm
\textwidth=190mm
\textheight=275mm
\headheight = 5mm
\headsep = 2mm
\footskip = 7mm

\titleformat{\part}[block]{}{}{1ex}%
  {\begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
    %\fill [Gold2,path fading=north] (0,-1) rectangle (\columnwidth,1.5);
    \node[fill=DarkGoldenrod1,rectangle,rounded corners,text=white,anchor=west,font=\huge\bfseries\sffamily] (a) at (0,0) {Part
               \thepart};
    \node[fill=none,text width= 0.7\columnwidth,text=red,anchor=north west,align=left,font=\huge\bfseries\sffamily] (b) at (a.north east) {#1};
   \begin{scope}[on background layer]
   \node[fill=Gold2,path fading=north]  [fit = (a)(b)] (B)  {};
    \node[pattern=vertical lines,pattern color=blue!50,path fading=north]  [fit = (a)(b)] (A)  {};
    \end{scope}
  \end{tikzpicture}%
  }
  []

\begin{document}
\part{The trends in art in XX}

\newpage\twocolumn
\part{The World Wars influence}

\newpage\onecolumn
\begin{multicols}{2}
\part{The IT influence}
\end{multicols}

\end{document}

在此处输入图片描述

如果没有explicit选项,你可以这样做(感谢 egreg)

首先定义

\newcommand{\mypart}[1]{%
  \begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
    \node[fill=DarkGoldenrod1,rectangle,rounded corners,text=white,anchor=west,font=\huge\bfseries\sffamily] (a) at (0,0) {Part
               \thepart};
    \node[fill=none,text width= 0.7\columnwidth,text=red,anchor=north west,align=left,font=\huge\bfseries\sffamily] (b) at (a.north east) {#1};
   \begin{scope}[on background layer]
   \node[fill=Gold2,path fading=north]  [fit = (a)(b)] (B)  {};
    \node[pattern=vertical lines,pattern color=blue!50,path fading=north]  [fit = (a)(b)] (A)  {};
    \end{scope}
  \end{tikzpicture}%
  }

然后声明\titleformat类似

\titleformat{\part}[block]{}{}{1ex}%
  {\mypart}
  []

完整代码如下:

\documentclass[a4paper,twoside]{article}

\usepackage[svgnames,x11names]{xcolor}
\usepackage{tikz}
\usetikzlibrary{fadings,patterns,backgrounds,fit}

\usepackage{titletoc}
\usepackage[toctitles,pagestyles]{titlesec}

\usepackage{multicol}

\oddsidemargin=-10.4mm
\evensidemargin=-20.4mm
\topmargin=-22mm
\textwidth=190mm
\textheight=275mm
\headheight = 5mm
\headsep = 2mm
\footskip = 7mm

\newcommand{\mypart}[1]{%
  \begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
    \node[fill=DarkGoldenrod1,rectangle,rounded corners,text=white,anchor=west,font=\huge\bfseries\sffamily] (a) at (0,0) {Part
               \thepart};
    \node[fill=none,text width= 0.7\columnwidth,text=red,anchor=north west,align=left,font=\huge\bfseries\sffamily] (b) at (a.north east) {#1};
   \begin{scope}[on background layer]
   \node[fill=Gold2,path fading=north]  [fit = (a)(b)] (B)  {};
    \node[pattern=vertical lines,pattern color=blue!50,path fading=north]  [fit = (a)(b)] (A)  {};
    \end{scope}
  \end{tikzpicture}%
  }

\titleformat{\part}[block]{}{}{1ex}%
  {\mypart}
  []

\begin{document}
\part{The trends in art in XX}

\newpage\twocolumn
\part{The World Wars influence}

\newpage\onecolumn
\begin{multicols}{2}
\part{The IT influence}
\end{multicols}

\end{document}

如果你想改变矩形的高度,可以,minimum height=2cm,yshift=0.5cm使用

\begin{scope}[on background layer]
   \node[fill=Gold2,path fading=north,minimum height=2cm,yshift=0.5cm]  [fit = (a)(b)] (B)  {};
    \node[pattern=vertical lines,pattern color=blue!50,path fading=north,minimum height=2cm,yshift=0.5cm]  [fit = (a)(b)] (A)  {};
    \end{scope}

在此处输入图片描述

相关内容