I use \includegraphics command to insert image to the document. But how can I add a border around this image w/o any margin between border lines and image?
It seems to be very easy, but I can't find it in the documentation.
-
3related : https://tex.stackexchange.com/q/133450/138900 – AndréC Dec 10 '19 at 09:05
7 Answers
You can add a frame around it by placing it inside a \fbox{...} command.
\fbox{\includegraphics[options]{image}}
The distance can be set by changing the \fboxsep length and the line width with the \fboxrule length, e.g. to draw a tight 1pt thick rule around the image use:
{%
\setlength{\fboxsep}{0pt}%
\setlength{\fboxrule}{1pt}%
\fbox{\includegraphics[options]{image}}%
}%
Using a recent version of my adjustbox package you can use:
\usepackage[export]{adjustbox}
% ...
\includegraphics[<your options>,frame]{image}% tight frame
% or
\includegraphics[<your options>,fbox]{image}% Like normal \fbox
There is also cframe and cfbox for colored frames. All of these allow for multiple optional values, e.g. frame=<rule width>. See the manual for more information.
- 262,582
-
6Thanks,
\frameworks better for me, because I don't need any margin between image and line. – TheBug Jun 13 '11 at 20:15 -
16I now programmed a
frameoption for\includegraphics. It will be released with the next package update ofadjustbox. – Martin Scharrer Jul 22 '11 at 08:16 -
2Pleasen i ask if it's possible to have rounded border corners? and how ? thank you. – researcher Sep 08 '12 at 11:49
-
1@researcher: For rounded corners you need to use TikZ or PS-Tricks. See also How to draw frame with rounded corners around box. – Martin Scharrer Sep 08 '12 at 12:16
-
1
-
@MartinScharrer can we use
\setkeys{Gin}{frame}? It doesn't seem to work for me. Maybe it should not beGin? I mean, I get no warning or error, just that otherGinoptions such aswidthno longer work (and no frame is shown) – Ciprian Tomoiagă Mar 13 '18 at 15:08 -
@CiprianTomoiagă: Using
Ginafter loading\usepackage[export]{adjustbox}should be ok. I would need to see you exact use case. Feel free to post a follow-up question with your MWE. – Martin Scharrer Mar 14 '18 at 06:24
I've found that \frame{\includegraphics{image}} command works for my case.
- 5,649
-
6Nice, I didn't know that
\frameexisted. I now figured out thatbeamerwhich defines its own\framemacro andframeenvironment also supports the normal\frameinside them (be saving and then restoring the default definition locally). – Martin Scharrer Jun 28 '11 at 17:25 -
3Note that
\framewill cause the final box to have no depth, which is fine for image but mostly not for text.{\setlength{\fboxsep}{0pt}\fbox{..}}however will keep the original depth, so that letters like 'y' and 'g' are not moved up. – Martin Scharrer Jul 22 '11 at 08:14 -
I found this to be problematic in Adobe. As you zoom in/out some sides of the box will dissapear – puk Jun 01 '20 at 23:47
-
1
You need more fancy frame? The settings that you can adjust:
\fboxsep=10mm%padding thickness
\fboxrule=4pt%border thickness
and
%\fcolorbox{bordercolor}{paddingcolor}{image}
\fcolorbox{red}{yellow}{\includegraphics[width=0.5\linewidth]{foobarbaz}}
\documentclass[demo]{article}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{blindtext}
\fboxsep=10mm%padding thickness
\fboxrule=4pt%border thickness
\begin{document}
\blindtext
\begin{figure}[hbtp]
\centering
%\fcolorbox{bordercolor}{paddingcolor}{image}
\fcolorbox{red}{yellow}{\includegraphics[width=0.5\linewidth]{foobarbaz}}
\caption{This is a black box for demo purpose.}
\label{fig:foobarbaz}
\end{figure}
\blindtext
\end{document}
- 46,933
-
3Thanks for such complete example, it will help me with my next experiments. – TheBug Jun 14 '11 at 15:26
A tcbox (or a tcolorbox) were missing in this list. Some simple examples:
\documentclass[a4paper]{article}
\usepackage[most]{tcolorbox}
\begin{document}
\tcbox{\includegraphics[width=5cm]{frog}}
\tcbox[colframe=green!30!black,
colback=green!30]{\includegraphics[width=5cm]{frog}}
\tcbox[sharp corners, boxsep=5mm, boxrule=1mm,
colframe=green!30!black, colback=white]
{\includegraphics[width=5cm]{frog}}
\end{document}
Update
An alternative to tcbox is tcbincludegraphics command:
\documentclass[a4paper]{article}
\usepackage[most]{tcolorbox}
\begin{document}
\tcbincludegraphics[width=5cm]{frog}
\tcbincludegraphics[colframe=green!30!black,
colback=green!30, graphics options={height=2cm}, width=.25\linewidth]{frog}
\tcbincludegraphics[hbox, size=fbox, graphics options={width=3cm}, sharp corners, colframe=red]{frog}
\end{document}
- 136,588
-
1Although this is the hardest solution, it is much better than the top rate solution by @theBug – puk Jun 02 '20 at 00:05
-
I wanted no margins, so
\tcbox[size=tight]{}was a great solution. – alphabetasoup Aug 23 '22 at 03:02
Somebody tell me if I've missed an answer already covering this, but my favourite way to do this is using efbox and this is my go-to image-framer for simple framing.
\documentclass[border=9pt]{standalone}
\usepackage{efbox,graphicx}
\efboxsetup{linecolor=green,linewidth=10pt}
\begin{document}
\efbox{\includegraphics{cath-gadael-chartref}}
\end{document}
[Disclaimer: code for the image is somewhere on this site, but it's mine so I don't feel obligated to find it.]
- 198,882
-
6
-
1@Schrödinger'scat Beats
example-image-a. I think themwepackage needs more cats! – cfr Dec 09 '19 at 22:59 -
1
-
1@Schrödinger'scat
example-image-purr,example-image-silent-glare,example-image-hiss,example-image-growl,example-image-prowl...? – cfr Dec 09 '19 at 23:03 -
-
-
-
For someone who wants to achieve a similar affect in ConTeXt,
\externalfigure accepts all the options of \framed, so one can draw a border using:
\externalfigure[file][frame=on]
- 62,301
I use this command.
\usepackage{graphicx}
\setlength{\fboxsep}{0.005pt}
\newcommand{\tmpframe}[1]{\fbox{#1}}
%\renewcommand{\tmpframe}[1]{#1}
use example:
\begin{figure}
\centering
\tmpframe{\includegraphics[width=0.99\linewidth]{images/pathToImage.png}}
\caption{Some caption text).}
\label{fig:myRef}
\end{figure}
If you want to print a picture without a frame, use renewcomand in comment.
- 121


