我正在运行以下代码
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools,siunitx}
\usepackage{amsmath}
\usepackage{xcolor}
\title{test}
\author{spanos.nikolaos }
\date{July 2020}
\begin{document}
\maketitle
\[ \text{Kelly MovieBot}: \colorbox{green!85}{\makebox(12,12){\textcolor{white}{}}} \\
& \text{And Chill}: \colorbox{cyan!85}{\makebox(12,12){\textcolor{white}{}}}\\
& \text{Movie Bot}: \colorbox{cyan!85}{\makebox(12,12){\textcolor{white}{}}} \]
\end{document}
但这些词语似乎并没有排成一行。
我迄今为止的输出:
期望输出(选项 1):
Kelly MovieBot:绿色矩形
And Chill:青色矩形
MovieBot:青色矩形
期望输出(选项 2):
在同一行,但至少在矩形和下一个关键字之间留有额外的空间。例如,
Kelly MovieBot:绿色矩形(空间) And Chill:青色矩形(空间) MovieBot:青色矩形
答案1
我建议您采用双列tabular
环境。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xcolor,booktabs}
\begin{document}
\[
\begin{tabular}{@{} rl @{}}
Kelly MovieBot & \colorbox{green!85}{\makebox(12,12){\textcolor{white}{}}} \\ \addlinespace
And Chill & \colorbox{cyan!85 }{\makebox(12,12){\textcolor{white}{}}} \\ \addlinespace
Movie Bot & \colorbox{cyan!85 }{\makebox(12,12){\textcolor{white}{}}}
\end{tabular}
\]
\end{document}
答案2
以下是两种尽可能简单的代码:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools,siunitx}
\usepackage{xcolor}
\title{test}
\author{spanos.nikolaos }
\date{July 2020}
\begin{document}
\maketitle
\noindent\makebox[\linewidth]{Kelly MovieBot: {\color{green!85}\rule[-6pt]{18pt}{18pt}}\qquad And Chill: {\color{cyan!85}\rule[-6pt]{18pt}{18pt}}\qquad
Movie Bot: {\color{cyan!85}\rule[-6pt]{18pt}{18pt}}
}
\vspace{1cm}
\noindent\makebox[\linewidth]{\begin{tabular}{ll}
Kelly MovieBot: & \color{green!85}\rule[-6pt]{18pt}{18pt}\\[1.5ex]
And Chill: & \color{cyan!85}\rule[-6pt]{18pt}{18pt}\\[1.5ex]
Movie Bot: & \color{cyan!85}\rule[-6pt]{18pt}{18pt}
\end{tabular}}
\end{document}