我想用 Tikz 创建一个矩形作为文本的背景。它将是我自定义标题页的标题。我分别创建了矩形节点和文本节点。我想根据文本的大小(自动)更改矩形的大小,但如果我写一段长文本,它就会从矩形中掉出来。我阅读了很多问题和答案以及 tikz 文档,但我无法解决它。在创建流程图时,矩形会根据文本大小而变化,情况类似。
(编辑)这是一个工作示例:(我使用 XeLaTeX)
\documentclass[12pt,a4paper]{report}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{fontspec}
\setmainfont{Arial}
\usepackage{anyfontsize}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture,overlay, inner sep=0pt,outer sep=0pt]
\node [rectangle,inner sep=0pt, fill=blue, anchor=north west, minimum width=198mm, minimum height=24.5mm,xshift=20mm,yshift=0mm]
(boxtitle) at (current page.west){};
\node[anchor = west, align = left, font=\bfseries, color=white,xshift=0mm] at (boxtitle.west)
{\fontsize{35}{1}\selectfont Headline headline headline\\ \\ \fontsize{35}{1}\selectfont headline headline \\ \\ \fontsize{36}{1}\selectfont headline headline};
\end{tikzpicture}
\end{document}
答案1
您不需要两个node
,而只需要一个:
\documentclass[12pt,a4paper]{report}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
%\usepackage{fontspec}
%\setmainfont{Arial}
\usepackage{anyfontsize}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[remember picture,overlay, inner sep=0pt,outer sep=0pt]
\node [rectangle,inner sep=0pt, fill=blue, anchor=north west, minimum width=198mm, minimum height=24.5mm,xshift=20mm,yshift=0mm,font=\bfseries, text=white,align=left]
(boxtitle) at (current page.west){\fontsize{35}{1}\selectfont Headline headline headline\\ \\ \fontsize{35}{1}\selectfont headline headline \\ \\ \fontsize{36}{1}\selectfont headline headline};
\end{tikzpicture}
\end{document}