15

My university requires that all figures in a thesis follow this pattern:

desired result

I'm very new to LaTeX, so far my best attempt has been this:

\begin{SCfigure}
    \colorbox{darkgray}{
         \begin{minipage}{14cm}
              \centering
              \includegraphics{inductor.jpg}
         \end{minipage}
    }
    \caption{caption caption}
\end{SCfigure}

and the result is here: result so far

My figure is not centered and the caption is off the page.

Trying to create another minipage around caption does not work because the colored box somehow appears in between the figure and caption.

Any help will be highly appreciated. Thank you!

3
  • "the image http://th.upic.me/i/dy/21untitled-1.jpg cannot be displayed because it contains errors" Nov 29, 2011 at 14:30
  • 2
    Welcome to TeX.sx! Please make sure that all images are uploaded using the official stackexchange interface, i.e. the image icon on top of the text field (shortcut: CTRL+G). This ensures that all images are always accessible and do not expire. (As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again.)
    – diabonas
    Nov 29, 2011 at 14:33
  • @wh1t3 images are fixed now
    – Pete
    Nov 29, 2011 at 15:37

3 Answers 3

11

All problems are not resolved. You need to create a macro to automate all the little jobs and I have not used Arial and 8pt. It will be fine to cretae a macro with argument the caption and the picture. I placed a minipage inside a minipage to get margins around the caption. I think there is perhaps a better way to this. I used a box to get the height of the picture, I don't know if it's possible to avoid this.

update 4: I added a macro like Herbert and I adapted the code to odd and even pages but you need to make some calculations to replace \hspace*{-6em} and \hspace*{-4em} by something like \hspace*{\dimexpr -\marginparwidth-\marginparsep\relax} (Herbert's code). I don't know exactly what are the macros for a twoside document to calculate the left and right margin. I corrected 2 bugs. I added some extra space around the picture

\documentclass[11pt]{book} 
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage{fourier,xcolor,graphicx} 
\usepackage[font={sf}]{caption} 
 \usepackage{ifthen,changepage,lipsum}

\newsavebox{\mybox}      

\DeclareCaptionLabelSeparator{period-newline}{.\newline\newline}
\captionsetup{aboveskip=3pt,singlelinecheck=false,
              labelsep=period-newline,labelfont={small,bf}} 
\newcommand\Image[4][width=\textwidth]{%
\savebox{\mybox}{\includegraphics[#1]{#2}} 
\fboxsep=0pt 
\checkoddpage  
\ifthenelse{\boolean{oddpage}}{%   
\hspace*{-25mm}  
\hbox{\colorbox{black!10}{\rule{0pt}{\dimexpr \ht\mybox+4mm}%
\begin{minipage}[b]{38mm}\center
 \begin{minipage}[b]{34mm}
   \caption[courte]{#3}
    \label{#4} 
 \end{minipage}%
\end{minipage}}%
\hspace*{2mm}
\colorbox{black!25}{%
\begin{minipage}[b]{145mm}\center
    \vspace*{2mm} 
\colorbox{white}{\usebox\mybox}%
  \vspace*{2mm}  
\end{minipage}}}%     
}{%   
  \hspace*{-40mm}%    
\hbox{\colorbox{black!25}{%
\begin{minipage}[b]{145mm}\center
  \vspace*{2mm}
\colorbox{white}{\usebox\mybox}%
 \vspace*{2mm}  
\end{minipage}}% 
\hspace*{2mm}  
\colorbox{black!10}{\rule{0pt}{\dimexpr \ht\mybox+4mm}%
\begin{minipage}[b]{38mm}\center
 \begin{minipage}[b]{34mm}
   \caption[courte]{#3}
    \label{#4}  
 \end{minipage}%
\end{minipage}}}% 
}   
}
\begin{document} 


\section {Figures/Capturing}

Place Tables/Figures/lmages in text as close to the reterence as possible. (see Figure 1). The table, frgure or image has to put in the area which is width 14.5 cm., filled with 70\% black colm. You should leave 2 mm. tram margin. In a side oox (width 3.8 cm., filled with 15\% Black), a short caption could be in the bottom. 

\begin{figure}[h!]               
 \Image[width=8cm]{elephant.pdf}{Long texte de légende avec quelques explications sur une figure importante}{elephant}  
\end{figure} 

ln tables, pictures, images or captures. use 10pt Arial regular to describe. Each f<gure (group) must include a caption set in 8-points Arial regular. The caption is to be on left or right depends on odd or even page. Figure numbering and referencing should be done sequentially, e.g. Figure. 1, Figure. 2, Table 1., Table 2 .. etc. for single figure and Figure l(a), Figure 1(b)., etc., for figures with multiple parts.    

\lipsum [1]
\section {Figures/Capturing}

\begin{figure}[h!]              
 \Image[width=8cm]{elephant.pdf}{Long texte de légende avec quelques explications sur une figure importante}{elephant bis}  
\end{figure} 
Compare with  the first picture \ref{elephant}
\end{document}  

enter image description here

10
  • 1
    @Pete Sorry I have not enough time to cretae a macro but an expert on this site will complete this beginning of solution. Nov 29, 2011 at 20:11
  • I tried your macro on twoside documenclass and it's not centered. Also, the caption has to be on the inside margin. Help a little bit more please!
    – Pete
    Nov 29, 2011 at 23:17
  • I forgot this condition. You need to adapt my code for the exact calculation of the left margin. Nov 30, 2011 at 5:35
  • I prefer the method tabularx of Herbert but I can't adapt some little things like \DeclareCaptionLabelSeparator to get exactly the same picture. Nov 30, 2011 at 5:46
  • Yes you can use \hspace*{-2.5cm} and \hspace*{-1.5cm} but a better approach is to make calculations like Herbert but you have to know all the parameters of the layout Nov 30, 2011 at 7:39
5

It needs two LaTeX runs to get the left/right pages correct

\documentclass[11pt]{article} 
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage[table]{xcolor}
\usepackage{graphicx,tabularx,ifthen} 
\usepackage{lipsum}     
\newcounter{ImageCounter}
\usepackage[font={small,sf},skip=-\normalbaselineskip]{caption}     
\renewcommand\tabularxcolumn[1]{b{#1}}
\newcommand\Image[3][width=\textwidth]{%
 \stepcounter{ImageCounter}\label{SpecialImage-\theImageCounter}%
 \ifthenelse{\isodd{\pageref{SpecialImage-\theImageCounter}}}%
  {\hspace*{-1cm}%\dimexpr -\marginparwidth-\marginparsep\relax}%
   \begin{tabularx}{\dimexpr \marginparwidth+\marginparsep+\textwidth+1cm\relax}%
     {@{}>{\columncolor{black!30}\centering} X @{\kern3pt} l 
         >{\columncolor{black!15}}b{1.3\marginparwidth} @{}}
    \includegraphics[#1]{#2} & & \caption{#3} 
   \end{tabularx}}%
  {\hspace*{\dimexpr -\marginparwidth-\marginparsep\relax}%
   \begin{tabularx}{\dimexpr \marginparwidth+\marginparsep+\textwidth+1cm\relax}%
     {@{}>{\columncolor{black!15}}b{1.3\marginparwidth} @{\kern3pt} l 
         >{\columncolor{black!30}\centering} X @{}}
   \caption{#3}  & & \includegraphics[#1]{#2}
   \end{tabularx}}%
}
\begin{document} 

\section {Figures/Capturing}
\lipsum[1]

\begin{figure}[!htb]
\Image[width=8cm,height=6cm]{tiger}{Some nonsense text for the also superfluos 
           caption of the tiger for the also superfluos caption of the tiger}  
\end{figure} 

\lipsum[1]

\begin{figure}[!htb]
\Image[width=8cm,height=6cm]{tiger}{Some nonsense text for the also superfluos 
           caption of the tiger for the also superfluos caption of the tiger}  
\end{figure} 

\lipsum[1]
\end{document}

enter image description here

11
  • Why all these calculations ? The specifications are 14.5 cm for the picture, 38 mm for the caption and 2mm for the interspace, but good idea for talularx, no need to calculate the height of the boxes. Nov 29, 2011 at 21:19
  • I have two problems with your code. There is a blank space at the top of the columns and the caption is not at the bottom of the first column. Nov 29, 2011 at 21:33
  • +1 Can this be adapted to behave differently on odd and even pages (as requested by the OP)
    – cmhughes
    Nov 29, 2011 at 22:59
  • @Herbert I tried your code on a twoside document and it's not centered. The caption also needs to be on the inside margin as well. Please take a look. Thanks!
    – Pete
    Nov 29, 2011 at 23:22
  • Is it possible to use \DeclareCaptionLabelSeparator with your method. I think you chose the best method with tabularx. Nov 30, 2011 at 5:49
1

To answer part of my own bounty, I found a solution with tcolorbox.

Happy to receive feedback to improve it.

Would be interested in having a solution with new tabularray (I could not change the text in the bounty).

![enter image description here

\documentclass{book}
\usepackage[most]{tcolorbox}
\usepackage{showframe}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{decorations.pathmorphing} 
\usetikzlibrary{patterns}
\tcbuselibrary{skins,breakable,raster,xparse}

\usepackage{geometry} 

\geometry{
    paper = a4paper,
    headheight = 14.1pt,
    left = 22.00mm, % left margin
    textwidth = 128mm, % main text block
    marginparsep = 4.0mm, % gutter 
    marginparwidth = 46.0mm % width of margin notes
}

\usepackage[
labelfont=sf,
hypcap=false,
format=hang,
%width=0.8\textwidth
]{caption}

\def\fullPage{\dimexpr \marginparwidth+\marginparsep+\textwidth\relax}

\newcommand{\testG}[4][] 
{
\tcbsidebyside[
    enhanced,   
    bicolor,
    before skip = 15pt,
    after skip = 15pt,
    coltext = orange!20!brown,
    toggle enlargement = evenpage, 
    grow to right by = \marginparwidth+\marginparsep, 
    sidebyside align = bottom,
    sidebyside gap = 2mm,
    colframe = gray!20,
    colframe = white,
    drop lifted shadow,
    segmentation style = {
        double = white,
        draw = white,
        double distance = 3pt,
        solid},
    if odd page = {
        sidebyside switch,
        lefthand width = \textwidth-0.5\marginparwidth, 
        colback = gray!5,
        colbacklower = gray!10,
    }%
    {%
    righthand width = \textwidth-0.5\marginparwidth,
    colback = gray!5,
    colbacklower = gray!10,
    before lower app = \centering,
    },
    boxrule = .5mm, 
    boxsep = 1mm, 
    left = 2pt,
    right = 4pt, 
    sidebyside gap = 1cm, 
    left skip = -1cm,
]{%
\captionof{figure}{#3}
    #4 % Some comments          
    }{%
\includegraphics[width = \textwidth,keepaspectratio]{#2}
}
            
}


\begin{document}

\chapter{Introduction}

                                            
\testG
{example-image-a}
{\lipsum[1][1]}
{\lipsum[1][1-3]}

                        
\newpage                        
                        
\testG
{example-image-b}
{\lipsum[2][1]}
{\lipsum[2]}


\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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