4

I want the text in left hand side to be equated to an inserted image on right hand side as shown below:enter image description here

Here, i wish the text in left hand side to be written in latex and equate it horizontally to an inserted image on right hand side. Also, how to insert text between images horizontally?

2 Answers 2

6

I am assuming by your use of the term "inserted image," that you have an external graphic. You can use \includegraphics (also) in math mode to insert images. To get them vertically aligned with the math axis, the easiest way is to apply \vcenter{\hbox{...}} to the graphic.

\documentclass{article}
\usepackage{amsmath,graphicx}
\begin{document}
\[
\begin{aligned}
G\oplus H &= \vcenter{\hbox{\includegraphics[height=3em]{example-image-a}}}
\oplus \vcenter{\hbox{\includegraphics[height=3em]{example-image-b}}}\\
&= \vcenter{\hbox{\includegraphics[height=3em]{example-image-c}}}
\end{aligned}
\]
\end{document}

enter image description here

egreg suggests the even simpler construction, using the valign key of \includegraphics (adjustbox package required):

\documentclass{article}
\usepackage{amsmath,graphicx}
\usepackage[export]{adjustbox}
\begin{document}
\[
\begin{aligned}
G\oplus H &= \includegraphics[height=3em,valign=c]{example-image-a}
\oplus \includegraphics[height=3em,valign=c]{example-image-b}\\
&= \includegraphics[height=3em,valign=c]{example-image-c}
\end{aligned}
\]
\end{document}
8
  • \begin{gathered}\includegraphics[...]{...}\end{gathered} is simpler, in my opinion.
    – egreg
    Apr 9, 2018 at 16:18
  • @egreg I note the vertical alignment, with your suggested change, is slightly different (i.e., uncentered). Apr 9, 2018 at 16:21
  • Indeed! There is a strut added, which raises the whole thing.
    – egreg
    Apr 9, 2018 at 16:27
  • @egreg Hmm. One of the few times that adding a \strut isn't helpful or at least innocuous. Apr 9, 2018 at 16:28
  • Here's a simpler construction then: \includegraphics[height=3em,valign=c]{example-image-b} (requires \usepackage[export]{adjustbox}). By the way, the example images have lowercase names; on some operating systems this may not make a difference, on others it could.
    – egreg
    Apr 9, 2018 at 16:30
2

You can do it with TikZ:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\tikzset{
  vcenter/.style={
    baseline={([yshift=-\the\dimexpr\fontdimen22\textfont2\relax]
                    current bounding box.center)},
  },
}

\begin{document}

\begin{equation*}
\begin{split}
G\oplus H &=
\begin{tikzpicture}[vcenter]
\coordinate (1) at (0,1);
\coordinate (2) at (0.866,0.5);
\coordinate (3) at (0,0);
\coordinate (c) at (1.732,0.5);
\fill (1) circle (1pt) node[above] {\tiny 1};
\fill (2) circle (1pt) node[left] {\tiny 2};
\fill (3) circle (1pt) node[below] {\tiny 3};
\fill (c) circle (1pt) node[right] {\tiny c};
\draw (1)--(2)--(3)--cycle;
\draw [red] (1)--(c);
\draw [red] (2)--(c);
\draw [red] (3)--(c);
\end{tikzpicture}
\oplus
\begin{tikzpicture}[vcenter]
\coordinate (a) at (0,1);
\coordinate (b) at (0,0);
\coordinate (c) at (0.866,0.5);
\fill (a) circle (1pt) node[above] {\tiny a};
\fill (b) circle (1pt) node[below] {\tiny b};
\fill (c) circle (1pt) node[right] {\tiny c};
\draw (a)--(b);
\draw [red] (a)--(c);
\draw [red] (b)--(c);
\end{tikzpicture}
\\
&=
\begin{tikzpicture}[vcenter]
\coordinate (1) at (0,1);
\coordinate (2) at (0.866,0.5);
\coordinate (3) at (0,0);
\coordinate (a) at (1.732,1);
\coordinate (b) at (1.732,0);
\coordinate (c) at (2.598,0.5);
\fill (1) circle (1pt) node[above] {\tiny 1};
\fill (2) circle (1pt) node[left] {\tiny 2};
\fill (3) circle (1pt) node[below] {\tiny 3};
\fill (a) circle (1pt) node[above] {\tiny a};
\fill (b) circle (1pt) node[below] {\tiny b};
\fill (c) circle (1pt) node[right] {\tiny c};
\draw (1)--(2)--(3)--cycle;
\draw (a)--(b);
\draw [red] (1)--(c);
\draw [red] (2)--(c);
\draw [red] (3)--(c);
\draw [red] (a)--(c);
\draw [red] (b)--(c);
\end{tikzpicture}
\end{split}
\end{equation*}

\end{document}

enter image description here

These are very simple diagrams and the code should be almost self-explaining. The style defined in the preamble is found in https://tex.stackexchange.com/a/302507/4427 and it copes with the alignment of the picture similar to the one suggested by Steven in his answer.

The idea is to define some coordinates and then use them for drawing circles and segments. Labels are placed as nodes next to the circles.

You must log in to answer this question.

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