0

Consider the code

\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}

And the output

enter image description here

QUESTION: How may I inserted the blue numbered box in a sentence (with the ability to adjust its vertical placement if need be) so that the sentence flows in a natural manner with it?

Note: If there is a more suitable way of producing the colored numbered box for this purpose, please advise so.

Thank you.

4
  • 2
    TikZ makes a box like TeX does it for letters, words and so on, so simply write your tikZ code where it shall appear. The other way is to use tcolorbox only. Commented Oct 15, 2021 at 20:40
  • @Harald Lichtenstein Thank you for your comment. Would you consider expanding it as a posted answer? Many thanks.
    – DDS
    Commented Oct 15, 2021 at 22:07
  • 1
    You can make this task with tcolorbox as well: tex.stackexchange.com/questions/433256/…
    – cis
    Commented Oct 16, 2021 at 2:37
  • @cis Thank you for providing this link.
    – DDS
    Commented Oct 16, 2021 at 2:38

2 Answers 2

3

You almost did it! Following code is yours code with an added optional parameter to change whatever option in \logo boxes.

\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}

enter image description here

1
  • Thank you for posting this answer.
    – DDS
    Commented Oct 16, 2021 at 14:05
1

Does something like this suits you?

insert tikz box in text

\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}

Feel free to play with inner sep if you want a bolder box.

2
  • Thank you for your answer. When I enlarge the box and make the text bold, the words are no longer aligned with the sentence text. This could be corrected if (1) I could lower the text in the box; or (2) I could vertically adjust the height of the box and its contents. However, with the replacement of my newtcbox{logo}, I have not been able to do either of these things. Would you apprise me of how I may do both of these things? Many thanks.
    – DDS
    Commented Oct 15, 2021 at 22:06
  • The vertical alignment is controled by the first optional argument of the command. In the above code, larger boxes is downed by -3pt instead of the default -2pt.
    – SebGlav
    Commented Oct 16, 2021 at 9:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .