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'm working on a layout for a custom textbook class, and I'm having issues getting this environment to work as I like.

Here's a shot of my current working layout:

enter image description here

I'd like to be able to make an environment so that a minipage is sitting left of the image and I can populate it with text if needed. I've tried using the environ package to do this, but the layout is not working, despite several tweaks.

Here's my page layout:

enter image description here

I'd like the left \minipage to use the margin notes space, and the right minipage to use the body.

I've tried using the following code, but it doesn't seem to want to work.

\documentclass{book}
\let\cleardoublepage\clearpage

\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage[strict]{changepage}
\usepackage{calc}
\usepackage{environ}
\usepackage[
  left=2.25in,
  right=0.75in,
  top=1.25in,
  bottom=1.25in,
  marginparwidth=1.75in,
  marginparsep=.25in,
  asymmetric]{geometry}

\NewEnviron{myfig}[2]{
  \begin{adjustwidth}{-2.0in}{0.25in}
    \begin{table}[h]
      \centering
      \makebox[0pt][c]{\parbox{\textwidth}{%
      \colorbox{lightgray}{
      \begin{minipage}{2.0in}
        #1\\#2
      \end{minipage}}
      \colorbox{cyan}{
      \begin{minipage}{\textwidth}
        \BODY
      \end{minipage}}
      }}
    \end{table}
  \end{adjustwidth}
  }


\makeatletter
\titleformat{\chapter}
  {\normalfont\sffamily\Huge\scshape}
  {}{0pt}
  {\thispagestyle{empty}    % Remove page number on new chapters
  \begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=cyan] (0,-1) rectangle
          (25cm,3cm);
        \draw[fill=cyan] (0,-24) rectangle
          (25cm,-25cm);
        \ifttl@label% <---------------------- Added condition on \ifttl@label
          \node[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
              {\color{white}\LARGE CHAPTER \Huge\thechapter};
        \fi% <------------------------------- end condition on \ifttl@label
        \node[anchor=west,xshift=.21\paperwidth,yshift=-.065\paperheight,rectangle]
              {\color{cyan}\Huge\MakeUppercase{#1}};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }
\makeatother

\begin{document}
  \chapter{test}
  \begin{myfig}{Label}{This is a description}
    foobar
  \end{myfig}
\end{document}

The above mwe produces the following:

enter image description here


EDIT: Thanks to help from Sašo Živanović, it's much closer to working... but there's an alignment issue I'd like to point out: I'd like the text description of the figure to show at the top left of the image. As of right now it's hovering at the bottom left.

enter image description here

share|improve this question
    
gray-box-around-figure-with-a-separate-gray-box-around-caption could be helpful here –  cmhughes Jan 31 '13 at 16:47
    
@cmhughes I've added the suggested visual aids. –  agent154 Jan 31 '13 at 17:00

1 Answer 1

up vote 4 down vote accepted
+100

Is this the result that you wanted?

resulting page

This was achieved with the following definition of the myfig environment (the rest of the code is the same).

\newbox\myfigbox  
\newenvironment{myfig}[1][]{%
  {\noexpandarg\IfStrEq{#1}{}{}{%
    \raisebox{-\height}{\makebox[0pt][r]{%
      \colorbox{lightgray}{
        \begin{minipage}[t]{2.0in}
          \formatlabeldesc#1\formatlabeldesc
        \end{minipage}%
      }%
      \hspace{0.4em}% set as needed
    }}%
  }}%
  \setbox\myfigbox=\hbox\bgroup
  \begin{minipage}[t]{\textwidth}%
}{%
  \end{minipage}\egroup
  \raisebox{-\height}{\colorbox{cyan}{\box\myfigbox}}%
}
\def\formatlabeldesc#1\\#2\formatlabeldesc{\textbf{#1}\\\textit{#2}}

In response to the comment, I've changed the argument signature in the above definition from two mandatory arguments to a single optional. (Thus, all is well if no label and description are given.) Regarding the keyval request, I would say it would just force you to type more: I suggest simply delimiting the label and the description with a \\. (This also gives you complete control over formatting, if you will ever need it.)

\begin{document}
  \chapter{test}
  \begin{myfig}[Label\\This is a description]
    foobar
  \end{myfig}
  \begin{myfig}
    foobar
  \end{myfig}
\end{document}

Fancy keyval version (using pgfkeys):

\usepackage{pgfkeys}
\pgfkeys{/myfig/.cd,
  label/.store in=\myfiglabel,
  description/.store in=\myfigdescription
}
\newbox\myfigbox
\newenvironment{myfig}[1][]{%
  {\noexpandarg\IfStrEq{#1}{}{}{%
    \def\myfiglabel{}\def\myfigdescription{}%
    \pgfkeys{/myfig/.cd,#1}%
    \raisebox{-\height}{\makebox[0pt][r]{%
      \colorbox{lightgray}{
        \begin{minipage}[t]{2.0in}
          \textbf{\myfiglabel}%
          \expandarg\IfStrEq{\myfiglabel}{}{}{\IfStrEq{\myfigdescription}{}{}{\\}}%
          \textit{\myfigdescription}%
        \end{minipage}%
      }%
      \hspace{0.4em}% set as needed
    }}%
  }}%
  \setbox\myfigbox=\hbox\bgroup
  \begin{minipage}[t]{\textwidth}%
}{%
  \end{minipage}\egroup
  \raisebox{-\height}{\colorbox{cyan}{\box\myfigbox}}%
}

% ...
\begin{myfig}[label=Label,description=This is a description]
  foobar
\end{myfig}
share|improve this answer
    
That looks about right... The margins look a little off, but I don't see that to be a difficult thing to adjust. I don't know if I had a reason to use environ... I do know some of my code does need it - I may have just used it for everything. –  agent154 Feb 10 '13 at 1:17
    
Could you possibly make two small adjustments: It would be nice to use a key/value pair of options to specify image label and description instead of two extra parameters. Also, if those are not included, I'd like to ensure that the document still compiles, but just without including any text at all in the margin. –  agent154 Feb 10 '13 at 1:25
    
I've also updated my question with a picture at the bottom. –  agent154 Feb 10 '13 at 1:33
    
If you still insist on the keyval, we can make it happen ;-) –  Sašo Živanović Feb 10 '13 at 2:01
    
I sort of like the idea of having the \\ in between the label and desc, but that means I can't apply different font styles to them - like bolding the label and italicizing the description. –  agent154 Feb 10 '13 at 2:08

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.