相对于锚点动态添加 tikz 节点

相对于锚点动态添加 tikz 节点

我正在尝试用 LaTeX 重建最初在 InDesign 中构建的简历,并得出结论,我必须重做它,因为我很可能找不到可以正确将 InDesign 文件(或 PDF)转换为 LaTeX 的工具。

澄清一下,这是我想要实现的目标在此处输入图片描述

我想通过添加嵌套的 tikzpicture 环境来实现这一点,以便能够包含多个职位。然而,我的问题是,我希望能够动态添加这些,而不需要每次都摆弄灰色框顶层之间的距离。这是我目前拥有的:

在此处输入图片描述

使用以下代码:

\documentclass{article}
\usepackage{tikz}
\usepackage[a4paper, left=5mm, right=5mm, top=20mm, bottom=20mm]{geometry}
\usepackage{xcolor}
\usepackage{amsmath} 

\definecolor{customblue}{HTML}{00b9f2}
\definecolor{customgray}{HTML}{f9f9fa}
\definecolor{customyellow}{HTML}{fede00}
\definecolor{customfontcolor}{HTML}{2c2e35}


% BoxText, BoxVerticalShift, Position, Department, Company, MonthStart, MonthEnd, JobDescription
\newcommand{\addYellowBox}[8]{%
    \node [fill=customyellow, minimum width=\textwidth-5mm, minimum height=2cm, anchor=north west, text depth=1\baselineskip, text=customfontcolor, yshift = #2] (yellowbox) at (mainbox.north west) {#1};
    \node [text=black, anchor=north west, xshift=2mm, yshift=-2mm, align=left] at (yellowbox.north west) {#3};
    \node [text=black, anchor=north west, xshift=2mm, yshift=-6mm, align=left] at (yellowbox.north west) {#4, #5};
    \node [anchor=north east, xshift=-2mm, yshift=-2mm, align=right] at (yellowbox.north east) {#6 - #7};
    \node [text=black, anchor=north west, xshift=2mm, yshift=-12mm, align=left] at (yellowbox.north west) {#8};
}

\newcommand{\addFirstBox}[8]{%
    \node [fill=customyellow, minimum width=\textwidth-5mm, minimum height=2cm, anchor=north west, text depth=1\baselineskip, text=customfontcolor, yshift = #2] (yellowbox) at (mainbox.north west) {#1};
    \node [text=black, anchor=north west, xshift=2mm, yshift=-2mm, align=left] at (yellowbox.north west) {#3};
    \node [text=black, anchor=north west, xshift=2mm, yshift=-6mm, align=left] at (yellowbox.north west) {#4, #5};
    \node [anchor=north east, xshift=-2mm, yshift=-2mm, align=right] at (yellowbox.north east) {Since #7};
    \node [text=black, anchor=north west, xshift=2mm, yshift=-12mm, align=left] at (yellowbox.north west) {#8};
}

\begin{document}
    \noindent
    \begin{tikzpicture}
        \node [fill=customblue, minimum width=5mm, minimum height=4cm, anchor=north] (bluebox) at (0,0) {};
        \node at (bluebox) [rotate=90, text=white, anchor=center] {Working Experience};
        \node [fill=customgray, minimum width=\textwidth-5mm, minimum height=2cm, anchor=north west, text depth=20\baselineskip, text=customfontcolor] (mainbox) at (bluebox.north east) {};

        \addFirstBox{Box 1}{0}{Position}{Department}{Company}{}{Jan 2002}{Job Description}
        \addYellowBox{Box 2}{-22mm}{Position}{Department}{Company}{Jan 2001}{Jan 2002}{Job Description}
        \addYellowBox{Box 3}{-44mm}{Position}{Department}{Company}{Jan 2000}{Jan 2001}{Job Description}
        \addYellowBox{Box 4}{-66mm}{Position}{Department}{Company}{Jan 2030}{Jan 2001}{Job Description}

    \end{tikzpicture}
\end{document}

  1. 我怎样才能正确地做到这一点?
  2. 最终,我会遇到灰色背景问题,需要手动扩展它。 更好的方法是删除灰色背景并将黄色背景颜色设置为灰色吗?

感谢您的帮助!

答案1

正如评论中所说,我建议使用 tcolorbox 包而不是 tikz。这样你就不必担心定位了:

\documentclass{article}
\usepackage[a4paper, left=5mm, right=5mm, top=20mm, bottom=20mm]{geometry}
\usepackage{xcolor}
\usepackage{amsmath} 

\definecolor{customblue}{HTML}{00b9f2}
\definecolor{customgray}{HTML}{f9f9fa}
\definecolor{customyellow}{HTML}{fede00}
\definecolor{customfontcolor}{HTML}{2c2e35}

\usepackage[most]{tcolorbox}

\newtcolorbox{foobox}[1]{
  sharp corners,
  enhanced,
  size=minimal,
  frame empty,
  colbacktitle=customblue,
  colback=lightgray,
  attach boxed title to top left={yshift=-\tcboxedtitleheight,xshift=-\tcboxedtitlewidth},
  boxed title style={frame empty, interior hidden,sharp corners,rotate=90},
  underlay boxed title={\fill[customblue] (interior.north west) rectangle ++(-\tcboxedtitlewidth,-\tcboxedtitleheight);},
  enlarge left by=\tcboxedtitlewidth,
  width=\linewidth-\tcboxedtitlewidth,
  height=\tcboxedtitleheight,
  height plus=\textheight,
  title=#1
}

\newtcolorbox{yellowbox}{
  sharp corners,
  enhanced,
  frame empty,
  colback=yellow,
}

\begin{document}

\begin{foobox}{Working Experience}
\begin{yellowbox}
Position \hfill Date

Department

Description
\end{yellowbox}

\begin{yellowbox}
Position \hfill Date

Department

Description
\end{yellowbox}

\begin{yellowbox}
Position \hfill Date

Department

Description
\end{yellowbox}
\end{foobox}

\end{document}

在此处输入图片描述

相关内容