在句子中放置彩色文本框

在句子中放置彩色文本框

考虑一下代码

\documentclass{book}
\usepackage{xcolor}
\usepackage{tcolorbox}
\usepackage[tikz]{bclogo}
\usetikzlibrary{calc,shapes.callouts,shapes.arrows}

\newtcbox{\logo}{nobeforeafter, notitle, %sharpcorners,
    colframe=blue,
    colback=blue,
    top=4pt,
    left=5pt,
    right=5pt,
    bottom=4pt,
    fontupper=\sffamily\bfseries,
    %colupper=green!30!black,
    tcbox raise base}
\begin{document}
\Large

% Numbered Box
\logo{\small{\textcolor{white}{1}}}

\vspace{20pt}

In this sentence (1) I would like to replace the previous `(1)' in this sentence by the above blue numbered box. Also, I would like to have the ability to adjust the box's vertical placement in the sentence to accommodate larger boxes. 
\end{document}

输出

在此处输入图片描述

问题:如何在句子中插入蓝色编号框(如果需要,可以调整其垂直位置),以便句子自然流动?

注:如果有更适合的方法来生产用于此目的的彩色编号盒,请告知。

谢谢。

答案1

您几乎成功了!以下代码是您的代码,其中添加了一个可选参数,用于更改\logo框中的任何选项。

\documentclass{book}
\usepackage{tcolorbox}

\newtcbox{\logo}[1][]{nobeforeafter, notitle, %sharpcorners,
    colframe=blue,
    colback=blue,
    top=4pt,
    left=5pt,
    right=5pt,
    bottom=4pt,
    fontupper=\sffamily\bfseries,
    colupper=white,
    %colupper=green!30!black,
    tcbox raise base,
    #1}
\begin{document}
\Large

% Numbered Box
\logo{\small{\textcolor{white}{1}}}

\vspace{20pt}

In this sentence \logo{(1)} I would like to replace the previous 
`(1)' in this sentence by the above blue numbered box. Also, I 
would like to have the \logo[fontupper=\sffamily\bfseries\Huge, 
colupper=orange]{ability} to adjust the box's vertical placement 
in the sentence to accommodate larger boxes. 
\end{document}

在此处输入图片描述

答案2

这样的事情适合你吗?

在文本中插入 tikz 框

\documentclass{article}
\usepackage{tikz}

\newcommand{\bbox}[2][-2]{\raisebox{#1 pt}{\tikz \node[rounded corners=2pt,inner sep=2pt, outer sep=0pt,fill=blue,text=white]{\footnotesize #2};}}

\begin{document}
    
In this sentence \bbox{1} I would like to replace the previous `(1)' in this sentence by the above blue numbered box. Also, I would like to have the ability to adjust the box's vertical placement in the sentence to accommodate \bbox[-3]{larger boxes}. 

\end{document}

inner sep如果您想要更大胆的盒子,请随意玩。

相关内容