![将文本一个接一个地放在另一个文本下方或放在同一行上但留有额外的空间 - 在数学公式中](https://linux22.com/image/419330/%E5%B0%86%E6%96%87%E6%9C%AC%E4%B8%80%E4%B8%AA%E6%8E%A5%E4%B8%80%E4%B8%AA%E5%9C%B0%E6%94%BE%E5%9C%A8%E5%8F%A6%E4%B8%80%E4%B8%AA%E6%96%87%E6%9C%AC%E4%B8%8B%E6%96%B9%E6%88%96%E6%94%BE%E5%9C%A8%E5%90%8C%E4%B8%80%E8%A1%8C%E4%B8%8A%E4%BD%86%E7%95%99%E6%9C%89%E9%A2%9D%E5%A4%96%E7%9A%84%E7%A9%BA%E9%97%B4%20-%20%E5%9C%A8%E6%95%B0%E5%AD%A6%E5%85%AC%E5%BC%8F%E4%B8%AD.png)
我正在运行以下代码
\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}