我想要字符 (xxx) 或 (yyy) 或 (zzz) 始终位于 2.rows 结尾的位置。我使用了 \hfill,但它不起作用。我的示例工作代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{tcolorbox}
\usepackage[dvipsnames]{xcolor}
%\usepackage{xcolor}
\tcbuselibrary{poster}
\usepackage{bbding}
\usepackage{pifont}
\usepackage{enumitem}
\begin{document}
\begin{tcbposter}[
poster = {
columns=1,
rows=2,
spacing=3mm,
height=14cm,
width=12cm,
},
]
\posterbox[colframe=red,width=4cm,height=4cm]{column=1}{
\begin{itemize}[leftmargin=1em]
\item a2 \\ \hfill \textcolor{blue}{x x x}%
\item b2\\
\hfill \textcolor{red}{y y y}%
\item cccc2 ccccc cccc ccc \\ \hfill \textcolor{green}{z z z}%
\end{itemize}
}
\end{tcbposter}
\end{document}
答案1
在这种情况下,不要使用\\
来产生换行符。请改用空行。
\documentclass{article}
\usepackage{tikz}
\usepackage{tcolorbox}
\usepackage{xcolor}
\tcbuselibrary{poster}
%\usepackage{xcolor}
\usepackage{bbding}
\usepackage{pifont}
\usepackage{enumitem}
\begin{document}
\begin{tcbposter}[
poster = {
columns=1,
rows=2,
spacing=3mm,
height=14cm,
width=12cm,
},
]
\posterbox[colframe=red,width=4cm,height=4cm]{column=1}{
\begin{itemize}[leftmargin=1em]
\item a2
\hfill \textcolor{blue}{x x x}%
\item b2
\hfill \textcolor{red}{y y y}%
\item c2
\hfill \textcolor{green}{z z z}%
\end{itemize}
}
\end{tcbposter}
\end{document}
使文本总是在第二行,我认为我们应该使用 Ti钾Z 代表这个。事实上,这有点像嵌套 Ti钾Z 图片,这不应该做,但这是必须的。我们将嵌套 Ti钾仔细查看Z图片。
\documentclass{article}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{poster}
\usepackage{bbding}
\usepackage{pifont}
\usepackage{enumitem}
\begin{document}
\begin{tcbposter}[
poster = {
columns=1,
rows=2,
spacing=3mm,
height=14cm,
width=12cm,
},
]
\posterbox[colframe=red,width=4cm,height=4cm]{column=1}{
\begin{itemize}[leftmargin=1em]
\item \tikz[baseline={(x.base)}] {
\node[text width=\linewidth,%draw,
inner sep=0pt,
text depth=\baselineskip,
align=justify] (x) {a1};
\node[inner sep=0pt,
anchor=base east,
font=\color{blue}] at (x.south east) {x x x};
}
\item \tikz[baseline={(x.base)}] {
\node[text width=\linewidth,
inner sep=0pt,
text depth=\baselineskip,
align=justify] (x) {This will break to two lines};
\node[inner sep=0pt,
anchor=base east,
font=\color{red}] at (x.south east) {x x x};
}
\item \tikz[baseline={(x.base)}] {
\node[text width=\linewidth,
inner sep=0pt,
text depth=\baselineskip,
align=justify] (x) {cccc2 ccccc cccc ccc};
\node[inner sep=0pt,
anchor=base east,
font=\color{green}] at (x.south east) {x x x};
}
\end{itemize}
}
\end{tcbposter}
\end{document}
如果你觉得它太长,也许你应该定义一个宏。请注意,惯于适用于 3 行或更多行文本。如果有 3 行,则必须使用text depth=2\baselineskip
而不是text depth=\baselineskip
。
答案2
\mbox{}
在每个 之前放置一个空的\hfill
。
\documentclass{article}
\usepackage{tikz}
\usepackage{tcolorbox}
%\usepackage[dvipsnames]{xcolor}
%\usepackage{xcolor}
\tcbuselibrary{poster}
%\usepackage{xcolor}
\usepackage{bbding}
\usepackage{pifont}
\usepackage{enumitem}
\begin{document}
\begin{tcbposter}[
poster = {
columns=1,
rows=2,
spacing=3mm,
height=14cm,
width=12cm,
},
]
\posterbox[colframe=red,width=4cm,height=4cm]{column=1}{
\begin{itemize}[leftmargin=1em]
\item a2 \\ \mbox{}\hfill \textcolor{blue}{x x x}%
\item b2\\
\mbox{}\hfill \textcolor{red}{y y y}%
\item c2 \\ \mbox{}\hfill \textcolor{green}{z z z}%
\end{itemize}
}
\end{tcbposter}
\end{document}