itemize 中的矩形绘制

itemize 中的矩形绘制

你能帮我得到最后的矩形吗?:

在此处输入图片描述

\documentclass{article}
\usepackage[showframe=true]{geometry}
\usepackage{enumitem}



\begin{itemize}[label=$\bullet$]
  \item Set a rank threshold K 
  \item Compute \% relevant in top K
  \item Ignore documents ranked lower than K
  \item Ex:
\end{itemize}
\end{document}

答案1

不是 TikZ,即使你将其标记为:

\documentclass{article}
\usepackage[showframe=true]{geometry}
\usepackage{enumitem}
\usepackage{xcolor}
\newcommand\ClrSquare[1]{\textcolor{#1}{\rule{7pt}{7pt}}}
\begin{document}


\begin{itemize}[label=$\bullet$]
  \item Set a rank threshold K 
  \item Compute \% relevant in top K
  \item Ignore documents ranked lower than K
  \item Ex: \ClrSquare{green}\ClrSquare{red}\ClrSquare{green}\ClrSquare{red}\ClrSquare{green}
\end{itemize}
\end{document}

在此处输入图片描述

如果你需要几个这样的东西,那么可以用循环更轻松地完成,例如pgffor

\documentclass{article}
\usepackage[showframe=true]{geometry}
\usepackage{enumitem}
\usepackage{xcolor,pgffor}
\newcommand\ClrSquare[1]{\textcolor{#1}{\rule{7pt}{7pt}}}
\newcommand\ClrSquares[1]{\foreach\x in{#1}{\ClrSquare{\x}}}
\begin{document}  
\begin{itemize}[label=$\bullet$]
  \item Set a rank threshold K 
  \item Compute \% relevant in top K
  \item Ignore documents ranked lower than K
  \item Ex: \ClrSquares{green,red,green,red,green}
\end{itemize}
\end{document}

相关内容