[Tex/LaTex] the minipage equivalent of `width=\linewidth` for \includegraphics

includegraphicsminipagewidth

width=\linewidth is acceptable input option to \includegraphics, but is not acceptable as input to minipage. What can we replace X with so that \begin{minipage}{X} has a similair width setting to \includegraphics[width=\linewidth]{file_name}?


The following code is meant to create a framed figure. It almost works except that I do not want the width of the minipage to be hard-coded in to be 12 cm.

\documentclass{article}
\usepackage{graphicx}

\begin{document}\begin{figure}[htbp]
    \centering
    \fbox{
        \begin{minipage}{12 cm}
            \includegraphics[width=\linewidth]{solution_count_satisfiability}
            \caption{caption}
        \label{label}
        \end{minipage}
    }
\end{figure}
\end{document}

Best Answer

Not sure what your question is about, simply changing 12cm with \linewidth does it, and, as David already pointed out, you need to subtract the separation and line width of \fbox from it, otherwise the box will be larger then the line width. Also \fbox{<linebreak> will cause a space be added, which will push the image a little to the left, so you need to mask it with a comment: \fbox{%.

The simplest way would be using adjustbox:

\documentclass{article}
\usepackage{adjustbox}% loads graphicx

\usepackage{mwe}% for example text only

\begin{document}

\blindtext

\begin{figure}[htbp]
    \begin{adjustbox}{minipage=\linewidth-2\fboxsep-2\fboxrule,fbox,center}
        \includegraphics[width=\linewidth]{example-image}
        \caption{caption}
        \label{label}
    \end{adjustbox}
\end{figure}

\blindtext

\end{document}

As Mico stated already, the centering (here done with the center key) is not really needed if the content is already as wide as the line. I added it for good measure as you might change the width later.

enter image description here