1

How do I add a text beside a figure and still have the figure align? I tried using the \includegraphics[left] and \includegraphics[right] commands but you can see the figures and text are still not aligned.

I am following the solution here Syntax similar to \centering for right and left?

\begin{figure*}
\centering
\subfloat{
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {Left Hand \includegraphics[width=0.9\textwidth,height=0.02\textwidth,trim={0 0 0 0},clip,left]{figures/qualitative/segmentation-l.png}};
\end{tikzpicture}}
\subfloat{
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {Right Hand \includegraphics[width=0.9\textwidth,height=0.02\textwidth,trim={0 0 0 0},clip,left]{figures/qualitative/segmentation-r.png}};
\end{tikzpicture}}
\end{figure*}

enter image description here

3
  • it is hard to guess what you want left to do, you can not just make up key names and expect they do something. \includegraphics is positioned in exactly the way a letter is positioned, Left hand X has X to the right of the text X Left hand has X to the left, same is true if you replace X by \includegraphics except you have width=0.9\textwidth so there is hardly any space for text. Aug 7, 2022 at 17:34
  • @DavidCarlisle i am following the solution posted in tex.stackexchange.com/questions/91566/… I just want the right end of the bar chart to be aligned and the text to be right aligned too
    – Kong
    Aug 7, 2022 at 17:54
  • well how can anyone know you have used a non standard package adding extra keys to a standard command unless you tell us?? you have been on the site long enough to know all examples should be complete so they show the problem nd do not rquire people to guess definitions. Aug 7, 2022 at 18:01

1 Answer 1

2

A simple alternative.

a

\documentclass{article}

\usepackage{graphicx}

\begin{document}
        
    \noindent\begin{tabular}{@{}rl}     
        Left Hand  &\includegraphics[width=0.9\textwidth,height=0.02\textwidth,trim={0 0 0 0},clip]{example-image-a}\\
        Right Hand &\includegraphics[width=0.9\textwidth,height=0.02\textwidth,trim={0 0 0 0},clip]{example-image-b}\\
    \end{tabular}   

\end{document}

Or using the package subcaption (or subfig) using two nodes, one for the "hands" and another for the figure.

\documentclass{article}

\usepackage{graphicx}

\usepackage{subcaption}% <<<<<<<<<<<<<<<<<

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\tikzset{
    Hands/.style={
    below left = 0.2ex and 3.0ex,
    anchor= east,
    inner sep=0,
    text width=15ex,  
    align = right, 
     },
}

\begin{figure}
    \centering
    \begin{subfigure}{\linewidth}
        \begin{tikzpicture}
            \node[inner sep=0] (image) {\includegraphics[width=0.9\textwidth,height=0.02\textwidth,trim={0 0 0 0},clip]{example-image-a}};
            \node[Hands] (label) at (image.west) {\strut Left Hand};
        \end{tikzpicture}
    \end{subfigure}\\
    \begin{subfigure}{\linewidth}
        \begin{tikzpicture}
            \node[inner sep=0] (image) {\includegraphics[width=0.9\textwidth,height=0.02\textwidth,trim={0 0 0 0},clip]{example-image-b}};
            \node[Hands] (label) at (image.west) {\strut Right Hand};
        \end{tikzpicture}
    \end{subfigure}
\end{figure}

\end{document}

You must log in to answer this question.

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