是否可以在普通文本中构造一个小的彩色填充框?框的大小应与字体大小相对应。
我需要它,因为我需要为我在其他地方构建的一些图形构建图例。
答案1
很\fontcharht
简单:
\documentclass{article}
\usepackage{xcolor}
\newcommand{\legendbox}[1]{%
\textcolor{#1}{\rule{\fontcharht\font`X}{\fontcharht\font`X}}%
}
\begin{document}
\legendbox{blue} This is some text \legendbox{red}
\Large\legendbox{blue} This is some text \legendbox{olive}
\Huge\legendbox{blue!60} This is some text \legendbox{green!20}
\end{document}
答案2
\documentclass{article}
\usepackage{xcolor}
\usepackage{scalerel}
\newcommand*{\mybox}[1][red]{\scalerel*{\textcolor{#1}{\rule{1ex}{1ex}}}{d}}
\begin{document}
\mybox[blue] This is some text \mybox{} Again \mybox[olive]
\Large\mybox[blue] This is some text \mybox{} Again \mybox[olive]
\Huge\mybox[blue] This is some text \mybox{} Again \mybox[olive]
\end{document}
如果没有scalerel
这个也可以工作,因为ex
使用了单位:
\documentclass{article}
\usepackage{xcolor}
\newcommand*{\mybox}[1][red]{\textcolor{#1}{\rule{1.5ex}{1.5ex}}}
\begin{document}
\mybox[blue] This is some text \mybox{} Again \mybox[olive]
\Large\mybox[blue] This is some text \mybox{} Again \mybox[olive]
\Huge\mybox[blue] This is some text \mybox{} Again \mybox[olive]
\end{document}
这里只要你1.5ex
按照自己的意愿设置一次就可以了。