# hfill for 2. row of itemize

i want to character(x x x) or (y y y) or (z z z) that always located in position of Ending of 2.rows. i used \hfill but it don't work. My Example working code:

\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}


Don't use \\ to produce a line break in this case. Use a blank line instead.

\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}


To make the text always in the 2nd line, I think we should employ TikZ for this. In fact, this is something like nesting TikZ pictures, which should not be done, but this is obligatory. We will nest TikZ pictures carefully.

\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}


If you find it too long, maybe you should define a macro. Note that this won't work well with 3 lines of text or more. If you have 3 lines, you have to use text depth=2\baselineskip instead of text depth=\baselineskip.

• Thank you. Please help if text is longer then xxx , yyy, zzz move to 3.row. I need that they always in ending of 2. row. Thanks – latexforti May 7 at 10:02
• @latexforti See my edited answer – user156344 May 7 at 10:07
• @latexforti So what if those variables go to the third line? I strongly think that manually adjusting is the best option here – user156344 May 7 at 10:11
• @latexforti Reset your leftmargin option of itemize to 0pt for example. – user156344 May 7 at 11:29
• Then do not use itemize at all. Just use a normal $\bullet$ in front of every text. itemize is supposed to align the second line with the first line – user156344 May 7 at 12:06

Place an empty \mbox{} prior to each \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}


• B Segletes thank for your answer. If text is longer, example "cccc cccc cccc ", then zzz located in 3. row, not 2.row – latexforti May 7 at 10:01
• @latexforti Well, if you want it to be on the 3rd line, why do you need line breaks then? – user156344 May 7 at 10:02
• @JouleV i want it display in 2.rows (3.rows = wrong). Each item split 2 rows. – latexforti May 7 at 10:04