1

Currently am facing two small issues.

Firstly, I made a custom command that lets me put an image on the left and text on the right. I called it \imtxtopt. It works pretty well except for one small problem.

The gap between miniboxes is non-existent.

Original Code (Code 1)

I nested both my miniboxes in another mini box, even that didn't help. Then I added a \vspace which helped my issue:

Code with nested miniboxes in one minibox and vspace

However, the issue now is that there is some extra space at the end of the each \imtxtopt (which is ok), which I don't want for the last \imtxtopt if I stack multiple \imtxtopt commands. I know I can created another command without the \vspace, but isn't it possible to have an if/else statement type solution? In short I want spacing between each \imtxtopt and between next paragraph and prior \imtxtopt to be consistent. I tried finding out if there is a way to add a separation between miniboxes in LaTeX globally, but no luck.

The second issue is, if I do not use the callouts package, I get the image size calculations as part of the text (Code 3):

No callouts package

Why is this and how can I avoid this? I only found this out when making the MWE since callouts is already included by default in my document, I didn't notice this was an issue.

Codes below:

Code 1:

% Default Template and Font Size
\documentclass{article}

 % Set Margins of the Document
\usepackage[a4paper,bindingoffset=0in,left=2.54cm,right=2.54cm,top=3.8cm,bottom=2.5cm,footskip=.25in]{geometry}

% Special container for image on left and text on right with options
\newcommand\imtxtopt[4]{
\begin{minipage}{#1}
    \centering
    \includegraphics[#2]{#3}
\end{minipage}\quad
\begin{minipage}{\textwidth-#1-1em}
#4
\end{minipage}
}

\usepackage{lipsum}

% Annotations
\usepackage{callouts}

\usepackage{graphicx}

\begin{document}

\section{Test 1}

\imtxtopt{2cm}{width=2cm}{example-image}{\lipsum[1]}
\imtxtopt{2cm}{width=2cm}{example-image}{\lipsum[1]}
\imtxtopt{2cm}{width=2cm}{example-image}{\lipsum[1]}

\lipsum[1]

\end{document}

Code 2:

% Default Template and Font Size
\documentclass{article}

 % Set Margins of the Document
\usepackage[a4paper,bindingoffset=0in,left=2.54cm,right=2.54cm,top=3.8cm,bottom=2.5cm,footskip=.25in]{geometry}

% Special container for image on left and text on right with options
\newcommand\imtxtopt[4]{
\begin{minipage}[H]{\textwidth}
\begin{minipage}{#1}
    \centering
    \includegraphics[#2]{#3}
\end{minipage}\quad
\begin{minipage}{\textwidth-#1-1em}
#4
\end{minipage}
\vspace{6pt}
\end{minipage}
}

\usepackage{lipsum}

% Annotations
\usepackage{callouts}

\usepackage{graphicx}

\begin{document}

\section{Test 1}

\imtxtopt{2cm}{width=2cm}{example-image}{\lipsum[1]}
\imtxtopt{2cm}{width=2cm}{example-image}{\lipsum[1]}
\imtxtopt{2cm}{width=2cm}{example-image}{\lipsum[1]}

\lipsum[1]

\end{document}

Code 3:

% Default Template and Font Size
\documentclass{article}

 % Set Margins of the Document
\usepackage[a4paper,bindingoffset=0in,left=2.54cm,right=2.54cm,top=3.8cm,bottom=2.5cm,footskip=.25in]{geometry}

% Special container for image on left and text on right with options
\newcommand\imtxtopt[4]{
\begin{minipage}{#1}
    \centering
    \includegraphics[#2]{#3}
\end{minipage}\quad
\begin{minipage}{\textwidth-#1-1em}
#4
\end{minipage}
}

\usepackage{lipsum}

% Annotations
%\usepackage{callouts}

\usepackage{graphicx}

\begin{document}

\section{Test 1}

\imtxtopt{2cm}{width=2cm}{example-image}{\lipsum[1]}
\imtxtopt{2cm}{width=2cm}{example-image}{\lipsum[1]}
\imtxtopt{2cm}{width=2cm}{example-image}{\lipsum[1]}

\lipsum[1]

\end{document}

1 Answer 1

0

The reason why, if you do not use the callouts package, you get the image size calculations as part of the text is that the image size calculations are not wrapped into \dimexpr...\relax.


The content of your minipages is vertically centered. This means: The baselines of the boxes formed from your minipages are vertically in the middle of these boxes. Thus these boxes have a great depth which affects the way in which LaTeX vertically places these boxes.

I suggest not to use minipages and instead do one's own box-measuring-thing for aligning the image while having the text in normal \vboxes whose depth will be the depth of the last line of text which they contain.

% Default Template and Font Size
\documentclass{article}

\newbox\mytempboxa
\newbox\mytempboxb

 % Set Margins of the Document
\usepackage[a4paper,bindingoffset=0in,left=2.54cm,right=2.54cm,top=3.8cm,bottom=2.5cm,footskip=.25in]{geometry}

\makeatletter
% Special container for image on left and text on right with options
\newcommand\imtxtopt[4]{%
  \setbox\mytempboxa=\vbox{%
    \hsize=#1\relax
    \centering
    \includegraphics[#2]{#3}%
  }%
  \setbox\mytempboxb=\vbox{%
    \hsize=\dimexpr\textwidth-\wd\mytempboxa-1em\relax
    \noindent#4%
  }%
  \ifdim\ht\mytempboxa<\ht\mytempboxb\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
  {%
    \setbox\mytempboxa=\vbox to \ht\mytempboxb{%
      \hsize=#1\relax
      \centering
      \vfill
      \includegraphics[#2]{#3}%
      \vfill
    }%
  }{%
    \setbox\mytempboxb=\vbox to \ht\mytempboxa{%
      \hsize=\dimexpr\textwidth-\wd\mytempboxa-1em\relax
      \vfill#4\vfill
    }%
  }%
  \par\hbox to\textwidth{%
    \box\mytempboxa\hfill\box\mytempboxb\strut
  }%
}%
\makeatother

\usepackage{lipsum}
\usepackage{graphicx}

\begin{document}

\section{Test 1}

\imtxtopt{2cm}{width=2cm}{example-image}{\lipsum[1]}
% Do whatever \vskip you want.
%\smallskip 
\imtxtopt{2cm}{width=2cm}{example-image}{\lipsum[1]}
% Do whatever \vskip you want.
%\smallskip 
\imtxtopt{2cm}{width=2cm}{example-image}{\lipsum[1]}

\lipsum[1]

\end{document}

enter image description here

1
  • Thanks a lot Ulrich! I didn't even know about \vbox command...learnt a lot of new stuff. I will give this a go :)
    – famakki1
    Oct 12, 2020 at 10:03

You must log in to answer this question.

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