tikzpicture 移动文本

tikzpicture 移动文本

这是一个后续问题文本、\backgroundcolor 和 \tikz 之间的重叠顺序

在下面的例子中,如何让 lipsum 的文本从页面的左上角开始?

确实,看起来 tikzpicture 将文本向下移动了......

\documentclass[a4paper]{article}
\usepackage[a4paper,
        left=0.2cm,
        right=0.2cm,
        top=0.1cm,
        bottom=0.2cm]{geometry}
\usepackage{paracol}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{tikz}


\begin{document}

% Gray background at the bottom
\begin{tikzpicture}[remember picture,overlay]
    \fill[gray!30] ([xshift=0cm,yshift=-0cm]current page.north west) rectangle  ([xshift=-12.5cm,yshift=0cm]current page.south east); % Adjust these dimensions
\end{tikzpicture}

% Yellow frame as a second layer
\begin{tikzpicture}[remember picture,overlay]
    \draw[draw=yellow,line width=0.7cm] ([xshift=0cm,yshift=-0cm]current page.north west) rectangle ([xshift=-0cm,yshift=0cm]current page.south east);
\end{tikzpicture}

% Text on top
\columnratio{0.4}
\begin{paracol}{2}
    \noindent\lipsum[1-3]
    \noindent\lipsum[2-6]
\end{paracol}

\end{document}

在此处输入图片描述

答案1

有几个问题:

  • tikzpictures 之间的空行将开始一个新段落(为什么首先要有两张 tikzpictures?)

  • 如果您不想在开始 paracols 之前添加额外的行,请将 tikzpicture 放在列的开头而不是前面。


\documentclass[a4paper]{article}
\usepackage[a4paper,
        left=0.2cm,
        right=0.2cm,
        top=0.1cm,
        bottom=0.2cm]{geometry}
\usepackage{paracol}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{tikz}


\begin{document}

% Text on top
\columnratio{0.4}
\begin{paracol}{2}
% Gray background at the bottom
    \noindent\begin{tikzpicture}[remember picture,overlay]
      \fill[gray!30] (current page.north west) rectangle  ([xshift=-12.5cm]current page.south east); % Adjust these dimensions
      \draw[draw=yellow,line width=0.7cm] (current page.north west) rectangle (current page.south east);
    \end{tikzpicture}%
    \lipsum[1-3]
    \noindent\lipsum[2-6]
\end{paracol}

\end{document}

答案2

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{lipsum} % For generating dummy text
\usepackage[most]{tcolorbox} % Load tcolorbox package

\newtcolorbox{outerbox}{
    colback=white, % Background color
    colframe=yellow, % Border color
    width=\textwidth, % Width of the box
    height fixed for=all, % Dynamically adjust height
    valign=center, % Vertical alignment
    halign=center, % Horizontal alignment
    fonttitle=\bfseries, % Font for the title
    title={}, % Title of the box
    enhanced, % Enhanced mode for more styling options
    boxrule=5pt % Thickness of the frame
}


% Define tcolorbox for the inner grey columns
\newtcolorbox{innerbox}{
    colback=gray!20!white, % Background color
    colframe=gray!70!black, % Border color
    width=\linewidth, % Width of the box
    height fill, % Allow box to expand vertically to fit content
    valign=center, % Vertical alignment
    halign=left, % Horizontal alignment
    breakable % Allow breaking across pages
}

\begin{document}

\begin{outerbox}
    \begin{minipage}[b][0.5\textheight]{0.5\textwidth}
        \begin{innerbox}
            \lipsum[1] % Dummy text for the left column
        \end{innerbox}
    \end{minipage}%
    \hfill % Space between columns
    \begin{minipage}[b][0.8\textheight]{0.5\textwidth}
        \begin{innerbox}
            \lipsum[4] % Dummy text for the right column (extended)
        \end{innerbox}
    \end{minipage}
\end{outerbox}

\end{document}

相关内容