1

I am trying to frame my figure using fbox but it ends up enlarging and ruining the format. How do I have fbox not enlarge the figure? For example \fbox(enlarge=False){\includegrahics...}And how do I have 2 fbox with separate colors ?

EDIT: I found out that using \frame{\includegraphics...} does not enlarge the figure. But how do I change the frame color?

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{float}
\usepackage{subfig}
\usepackage{tikz}% loads graphicx

\begin{document}
\makeatletter
\newcommand{\definetrim}[2]{%
  \define@key{Gin}{#1}[]{\setkeys{Gin}{trim=#2,clip}}%
}
\makeatother

\definetrim{kit_mocap}{0 0 0 0} % {left bottom right top}
\def\barheight{0.015}
\def\imagewidth{0.12\textwidth}
\def\imagehspace{\hspace{-0.2em}}
\def\imagevspace{\vspace{-0.3cm}}
\setlength{\fboxrule}{1pt}
\setlength{\fboxsep}{0pt}

\begin{figure*}[ht]
\centering
\subfloat{
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagevspace

\subfloat{
\begin{tikzpicture}[remember picture]
    \node[inner sep=0] (image1) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south west,inner sep=0] (image2) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[inner sep=0] (image3) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south west,inner sep=0] (image4) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south west,inner sep=0] (image5) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south west,inner sep=0] (image6) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south west,inner sep=0] (image7) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south west,inner sep=0] (image8) at (0,0) {\includegraphics[width=\imagewidth,kit_mocap,clip]{example-image-a}};
\end{tikzpicture}}\imagevspace

\subfloat{
\begin{tikzpicture}[remember picture]
    \node[inner sep=0] (image1) at (0,0) {\fbox{\includegraphics[width=\imagewidth,clip]{example-image-a}}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south west,inner sep=0] (image2) at (0,0) {\fbox{\includegraphics[width=\imagewidth,clip]{example-image-a}}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[inner sep=0] (image3) at (0,0) {\includegraphics[width=\imagewidth,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south west,inner sep=0] (image4) at (0,0) {\includegraphics[width=\imagewidth,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south west,inner sep=0] (image5) at (0,0) {\includegraphics[width=\imagewidth,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south west,inner sep=0] (image6) at (0,0) {\includegraphics[width=\imagewidth,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south west,inner sep=0] (image7) at (0,0) {\includegraphics[width=\imagewidth,clip]{example-image-a}};
\end{tikzpicture}}\imagehspace
\subfloat{
\begin{tikzpicture}[remember picture]
    \node[anchor=south west,inner sep=0] (image8) at (0,0) {\includegraphics[width=\imagewidth,clip]{example-image-a}};
\end{tikzpicture}}

\end{figure*}

\end{document}

enter image description here

1 Answer 1

1

With a predefined image width (via \imagewidth in your example), you can set the boxed image inside a \makebox[\imagewidth]{\fbox{...}}:

enter image description here

\documentclass{article}

\usepackage{graphicx}

\begin{document}


\begin{figure}
  \setlength{\fboxrule}{1pt}%
  \setlength{\fboxsep}{0pt}%
  \def\imagewidth{0.12\textwidth}%

  \centering
  \includegraphics[width=\imagewidth]{example-image-a}
  \makebox[\imagewidth]{\fbox{\includegraphics[width=\imagewidth]{example-image-a}}}
  \includegraphics[width=\imagewidth]{example-image-a}
  \includegraphics[width=\imagewidth]{example-image-a}
  \includegraphics[width=\imagewidth]{example-image-a}
  \includegraphics[width=\imagewidth]{example-image-a}
  
  \addvspace{.2\baselineskip}

  \includegraphics[width=\imagewidth]{example-image-a}
  \includegraphics[width=\imagewidth]{example-image-a}
  \makebox[\imagewidth]{\fbox{\includegraphics[width=\imagewidth]{example-image-a}}}
  \includegraphics[width=\imagewidth]{example-image-a}
  \includegraphics[width=\imagewidth]{example-image-a}
  \includegraphics[width=\imagewidth]{example-image-a}

  \addvspace{.2\baselineskip}

  \includegraphics[width=\imagewidth]{example-image-a}
  \includegraphics[width=\imagewidth]{example-image-a}
  \includegraphics[width=\imagewidth]{example-image-a}
  \includegraphics[width=\imagewidth]{example-image-a}
  \makebox[\imagewidth]{\fbox{\includegraphics[width=\imagewidth]{example-image-a}}}

  \addvspace{.2\baselineskip}

  \includegraphics[width=\imagewidth]{example-image-a}
  \makebox[\imagewidth]{\fbox{\includegraphics[width=\imagewidth]{example-image-a}}}
  \includegraphics[width=\imagewidth]{example-image-a}
\end{figure}

\end{document}

If it affects vertical alignment, you can also incorporate \smash.

3
  • why in your example do I lose the spacing between figures if I place 8 figures in a row and use the \hspace variable after every figure?
    – Kong
    Apr 26, 2023 at 23:59
  • 1
    @Kong: Because you're necessarily inserting a negative space (-0.2em), rather than a regular inter-word space. There is no need to use your tikzpicture setup to just place the images, nor using \subfloat, since you're not using a sub-caption.
    – Werner
    Apr 27, 2023 at 0:20
  • Technically, shouldn't you also use \raisebox{0pt}[\dimexpr \height-\fboxrule][\dimexpr \depth-\fboxrule]{...} to keep the interline spacing constant? Apr 27, 2023 at 2:00

You must log in to answer this question.

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