Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

4 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.

share|improve this answer
    
Thanks, \frame works better for me, because I don't need any margin between image and line. –  TheBug Jun 13 '11 at 20:15
1  
I now programmed a frame option for \includegraphics. It will be released with the next package update of adjustbox. –  Martin Scharrer Jul 22 '11 at 8:16
    
Pleasen i ask if it's possible to have rounded border corners? and how ? thank you. –  researcher Sep 8 '12 at 11:49
    
@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 8 '12 at 12:16
add comment

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}}

enter image description here

\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}
share|improve this answer
1  
Thanks for such complete example, it will help me with my next experiments. –  TheBug Jun 14 '11 at 15:26
add comment
up vote 16 down vote accepted

I've found that \frame{\includegraphics{image}} command works for my case.

share|improve this answer
1  
Nice, I didn't know that \frame existed. I now figured out that beamer which defines its own \frame macro and frame environment also supports the normal \frame inside them (be saving and then restoring the default definition locally). –  Martin Scharrer Jun 28 '11 at 17:25
1  
Note that \frame will 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 8:14
add comment

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]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.