0

My float border, regardless of the image size, is always wider than the textwidth. Reducing the textwidth percentage simply makes the vertical size small (as it keeps aspect ratio) but does not make the float border any smaller See image, note the border extends beyond the textwidth:

reducing the textwidth percentage simply makes the vertical size

%DOCUMENT PREPPING%
%Defines Document Class
\documentclass[]{article}
%Load requried packages
\usepackage[british]{babel}
\usepackage{csquotes}
\usepackage{hyperref}
\usepackage[style=apa,sortcites=true,sorting=nyt,backend=biber]{biblatex}
\usepackage{lipsum}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{placeins}
\usepackage{float}
%defines foats (i.e. figures/pictures) as having a border
\floatstyle{boxed} 
\restylefloat{figure}
%Assigns image directory
\graphicspath{ {images/}}
%declares language mapping
\DeclareLanguageMapping{british}{british-apa}
%defines bib files
\addbibresource{C:/Users/20511181/Google Drive/Learning/Reviews/library.bib}
%Defines command to hide @ for email spam
\newcommand{\at}{\makeatletter @\makeatother}
%
%Figure Information. Note, DOCUMENT INFO OMITTED%
\begin{figure}[!ht]
    \includegraphics[trim=0cm 0cm 10cm 0cm, width=0.6\textwidth]{workloadcurve.png}
    \caption{Hypothesised workload curve from \parencite{Hart1988}.}
\end{figure}
\FloatBarrier

Example document:

%DOCUMENT PREPPING%
%Defines Document Class
\documentclass[]{article}
%Load requried packages
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{float}
%defines foats (i.e. figures/pictures) as having a border
\floatstyle{boxed} 
\restylefloat{figure}
%DOCUMENT INFORMATION%
%Title Information
\title{Image Test}
\author{Test}
\date{Last Updated: November, 2015}
%Begin document
\begin{document}
\maketitle
%start first section
\section{Introduction}
\clearpage

\begin{figure}[!htb]
    \includegraphics[width=0.8\textwidth]{example-image.jpg}
    \caption{The paper and pencil version of the NASA-TLX.}
\end{figure}

\end{document}
  • Welcome to the site! It would help if you made your example a document that people could test (removing presumably irelevant packages such as lipsum, csquotes etec, and using ``example-image` as the image name (which is a sample image that most people have already in their tex distribution) – David Carlisle Nov 19 '15 at 09:02
  • 1
    unrelated but \newcommand{\at}{\makeatletter @\makeatother} is equivalent to \newcommand{\at}{@} – David Carlisle Nov 19 '15 at 09:03
  • Is there a suggested protocol for uploading an example document? – Doctor David Anderson Nov 19 '15 at 09:12
  • Weirdly in the example image, the border is going wider than the textwidth. This perplexes me. – Doctor David Anderson Nov 19 '15 at 09:21
  • In the complete document as posted in the edited question the border is textwidth exactly. – David Carlisle Nov 19 '15 at 09:28
  • I suspect it is the trim=0cm 0cm 10cm 0cm which is forcing things, try deleting that. – David Carlisle Nov 19 '15 at 09:29
  • If you use trim, then add the option clip. – Fran Nov 19 '15 at 09:34
  • Add clip option did not resolve. – Doctor David Anderson Nov 19 '15 at 09:38
  • It's certainly something to do with \floatstyle{boxed} it just is stubborn and refuses to make it fit around the image when the image is scaled. Apparently it is a problem with floatstyle http://tex.stackexchange.com/questions/25016/figures-with-borders-problem http://tex.stackexchange.com/questions/32457/make-all-figures-and-tables-framed-by-default But why does it work fine in the sample? I do not know. – Doctor David Anderson Nov 19 '15 at 09:42

1 Answers1

0

The float boxed style is always slightly wider than \textwidth. If you don't want the box around the caption, just put an \fbox{..} around the image.

\documentclass{article}
\usepackage{showframe}
\usepackage{mwe}

\begin{document}

\begin{figure}
\fboxsep=1em
\fboxrule=1pt
\fbox{\begin{minipage}{\dimexpr \textwidth -2\fboxsep-2\fboxrule}
\centering\includegraphics[width=0.8\textwidth]{example-image}%
\caption\blindtext
\end{minipage}}
\end{figure}

\end{document}

full page with frame


Here I implemented everything as an environment.

\documentclass{article}
\usepackage{environ}
\usepackage{showframe}
\usepackage{mwe}

\NewEnviron{boxedfigure}[1][]%
{\begin{figure}[#1]%
 \fboxsep=1em
 \fboxrule=1pt
 \fbox{\begin{minipage}{\dimexpr \textwidth-2\fboxsep-2\fboxrule}
 \BODY
 \end{minipage}}%
\end{figure}}

\begin{document}

\begin{boxedfigure}
\centering\includegraphics[width=0.8\textwidth]{example-image}%
\caption\blindtext
\end{boxedfigure}

\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120