[Tex/LaTex] How to make boxes like these

boxesformattingtcolorboxtikz-styles

I'd like to have custom commands for making boxes that look like the Wolfram|Alpha entities in Mathematica notebooks:

\LinguisticAssistant{france}
\Entity{France}{country}

enter image description here
enter image description here

I've done the work of finding the colors, and defined them in my code. The fonts are as follows:
– LinguisticAssistant: (the first box with the orange equals sign) uses Ariel
– Entity: this uses bold and then smaller all-caps Helvitica.

This what I have so far:

\documentclass{article}
\usepackage{pstricks}
\usepackage{xcolor}
\definecolor{lightyellow}{RGB}{255, 250, 236}
\definecolor{textdark}{RGB}{100, 52, 20}
\definecolor{borderorange}{RGB}{253, 129, 36}
\definecolor{lightgray}{RGB}{214, 214, 214}
\definecolor{countrygray}{RGB}{153, 153, 153}
\begin{document}
\begin{pspicture}(5,5)
  \psset{fillstyle=solid, framearc=.4, linecolor=borderorange, linewidth=.8pt}
  \psframebox[fillcolor=lightyellow]{\textcolor{textdark}{France}  \textcolor{countrygray}{COUNTRY}}
\hspace{1cm}
  \psset{fillstyle=solid, framearc=.2, linecolor=lightgray, linewidth=.4pt}
  \psframebox[fillcolor=white]{\textcolor{black}{france}}
\end{pspicture}
\end{document}​

enter image description here

But I still don't know how to:

  • make the little equal sign
  • scale/format the text to look just like the images

I'm looking at the package tcolorbox now, not sure if it is easier or better than pstricks.

Update:

I made the equal sign icon as a little pdf.

Best Answer

It's been a while since I've used pstricks, so I'll leave that for someone else to address. Also, I'm not fluent in using tcolorbox. So, that too I'll leave for someone else. But, I will show how you can do this from TikZ

This answer is broken into five parts:

  • How to draw the France COUNTRY box. This is the most straight-forward.
  • How to draw the Equal france box. I use a few more subtle tricks here.
  • Customizing your own colors using RGB specifications.
  • Using your own image file to create an Equal france box-like result
  • Implementing this with macros

Box for "France COUNTRY"

enter image description here

\documentclass[tikz,border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand\makegray[1]{\color{gray}{#1}}
\begin{document}

\begin{tikzpicture}

  \node[rounded corners,
        draw=orange,
        fill=orange!25,text=black,font=\sffamily]
       {France \makegray{COUNTRY}};

\end{tikzpicture}

\end{document}

Box for "Equal france"

enter image description here

\documentclass[tikz,border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit}

\newcommand\makegray[1]{\color{gray}{#1}}

\newsavebox\aeequalsign
\begin{lrbox}\aeequalsign
  \begin{tikzpicture}[x={(4pt,0)},
                      y={(0,4pt)}]
    \fill[orange] (0,0) rectangle (5,3);
    \draw[white,line width=2pt] (1,1) -- ++ (3,0);
    \draw[white,line width=2pt] (1,2) -- ++ (3,0);
  \end{tikzpicture}
\end{lrbox}

\begin{document}

\begin{tikzpicture}

  \node[inner sep=0pt]            (AEEQUAL)                  {\usebox{\aeequalsign}};
  \node[anchor=west,
        font=\sffamily\bfseries]  (FRANCE) at (AEEQUAL.east) {france};
  \node[fit=(AEEQUAL) (FRANCE),inner ysep=5pt,inner xsep=0pt] (COMBINED) {};
  \draw[rounded corners=4pt]
        (AEEQUAL.north) |- (COMBINED.north east)
                        -- (COMBINED.south east) -| (AEEQUAL.south);

\end{tikzpicture}

\end{document}

Colors:

If you don't like my colors, you can define your own, much like you did with pstricks using the \definecolor macro provided with xcolor (which is automatically loaded with TikZ).

\definecolor{<color name>}{rgb}{<decimal>,<decimal>,<decimal>}
\definecolor{<color name>}{RGB}{<int>,<int>,<int>}

Here is an implementation for this in TikZ:

\tikzset{define color/.code 2 args={\definecolor{#1}{RGB}{#2}}}

Then you can write

\begin{tikzpicture}
  [
    define color={borderorange}{253,129,36},
    define color={lightyellow}{255,250,236},
  ]

  \node[rounded corners,
        draw=borderorange,
        fill=lightyellow,text=black,font=\sffamily\bfseries]
       {France \makegray{COUNTRY}};

\end{tikzpicture}

Including image files:

If you have an image file you would already like to include, that's straight-forward.

enter image description here

Just repurpose the code above for the equal sign as follows:

\newsavebox\aeequalsign
\begin{lrbox}\aeequalsign
  \includegraphics[width=2em]{image/no_you_cant}
\end{lrbox}

Macros for in-text implementation

I've created your macros

\LinguisticAssitant
\Entity

to allow you to more easily create something like the following:

enter image description here

I've also added a couple more features: in particular, I've taken into account that these might be used in-line (as in the image above), so I set the baseline for the graphic to match the textual baseline. Also, I've added the following line to \LinguisticAssistant

\path (COMBINED.north) ++ (0,\lineskip) node[inner sep=0pt] {};

which should avoid the appearance of this image crashing into the line above it.

You can add something similar to the bottom too

\path (COMBINED.south) ++ (0,-\lineskip) node[inner sep=0pt] {};

if you wish to add more space below the image. But, I've not done that with this code. Additionally, you can tweak the inner sep to create a more rigid space.

This was executed using

\documentclass{article}
\usepackage{lipsum}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit}

\newcommand\makegray[1]{\color{gray}{#1}}

\newsavebox\aeequalsign
\begin{lrbox}\aeequalsign
  \includegraphics[height=3ex]{image/no_you_cant}
\end{lrbox}

\tikzset{define color/.code 2 args={\definecolor{#1}{RGB}{#2}}}
\tikzset{define color={borderorange}{253,129,36},
         define color={lightyellow}{255,250,236},
        }

\newcommand\Entity[2]{%%
  \begin{tikzpicture}[baseline={(EQUALITY.base)}]
    \node[rounded corners,
          draw=borderorange,
          fill=lightyellow,text=black,font=\sffamily\bfseries]
         (EQUALITY)
         {#1 \makegray{#2}};
  \end{tikzpicture}}

\newcommand\LinguisticAssistant[1]{%%
\begin{tikzpicture}[baseline={(FRANCE.base)}]
  \node[inner sep=0pt]            (AEEQUAL)                  {\usebox{\aeequalsign}};
  \node[anchor=west,
        font=\sffamily\bfseries]  (FRANCE) at (AEEQUAL.east) {#1};
  \node[fit=(AEEQUAL) (FRANCE),inner ysep=5pt,inner xsep=0pt] (COMBINED) {};
  \draw[rounded corners=4pt]
        (AEEQUAL.north) |- (COMBINED.north east)
                        -- (COMBINED.south east) -| (AEEQUAL.south);
  \path (COMBINED.north) ++ (0,\lineskip) node[inner sep=0pt] {};
\end{tikzpicture}}


\begin{document}

  \LinguisticAssistant{ARMA} \Entity{virumque}{cano}, Troiae qui primus ab oris
  Italiam, fato profugus, Laviniaque venit
  litora, multum ille et terris iactatus et alto
  vi superum saevae memorem Iunonis ob iram;
  multa quoque et bello passus, dum conderet urbem,
  inferretque deos Latio, genus unde Latinum,
  Albanique patres, atque altae moenia Romae.

  \LinguisticAssistant{Musa}, \Entity{mihi}{causas memora}, quo numine laeso,
  quidve dolens, regina deum tot volvere casus
  insignem pietate virum, tot adire labores
  impulerit.  Tantaene animis caelestibus irae?

  \LinguisticAssistant{Urbs} \Entity{antiqua}{fuit}, Tyrii tenuere coloni,
  Karthago, Italiam contra Tiberinaque longe
  ostia, dives opum studiisque asperrima belli;
  quam Iuno fertur terris magis omnibus unam
  posthabita coluisse Samo; hic illius arma,
  hic currus fuit; hoc regnum dea gentibus esse,
  si qua fata sinant, iam tum tenditque fovetque.
  Progeniem sed enim Troiano a sanguine duci
  audierat, Tyrias olim quae verteret arces;
  hinc populum late regem belloque superbum
  venturum excidio Libyae:  sic volvere Parcas.
  Id metuens, veterisque memor Saturnia belli,
  prima quod ad Troiam pro caris gesserat Argis---
  necdum etiam causae irarum saevique dolores
  exciderant animo:  manet alta mente repostum
  iudicium Paridis spretaeque iniuria formae,
  et genus invisum, et rapti Ganymedis honores.
  His accensa super, iactatos aequore toto
  Troas, reliquias Danaum atque immitis Achilli,
  arcebat longe Latio, multosque per annos
  errabant, acti fatis, maria omnia circum.
  Tantae molis erat Romanam condere gentem!

\end{document}
Related Question