\documentclass{article}
\usepackage{tikz}
\newcommand\round[2]{\par
\noindent\begin{tikzpicture}%
\node[draw = #1, fill = #1, rectangle, rounded corners,
minimum size = 5.5mm, text = white, text width = \textwidth](char){#2};
\end{tikzpicture}\par%
}%
\begin{document}
\round{black}{\begin{center}
\textbf{Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello}
\end{center}}
\end{document}
为什么顶部框和第一行文本之间有垂直空间?
如何删除它?
我想:
答案1
假设所有\round
框中的文本都必须居中。如果此假设成立,则您可以通过节点样式选项将文本置于节点中心align=center
。同样,您可以定义文本为粗体:
\documentclass{article}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{tikz}
\newcommand\round[2]{\par
\noindent\begin{tikzpicture}%
\node[draw=#1, fill=#1, rounded corners, ,
font=\bfseries, text = white,
text width=\textwidth -
2*\pgfkeysvalueof{/pgf/inner xsep},
align=center
] (char) {#2};
\end{tikzpicture}\par%
}%
\begin{document}
\round{black}{\bfseries
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
}
\end{document}
(红线表示页面布局)。
答案2
由于 OP 想要一个\textwidth
节点,我建议使用tcolorbox
默认创建的宽度等于的框\textwidth
。
\documentclass{article}
\usepackage{tcolorbox}
\newtcolorbox{mybox}[1][]{%
colback=black, colframe=black, colupper=white, halign=center, #1
}
\begin{document}
\noindent\begin{mybox}
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello
\end{mybox}
\end{document}