views:

51

answers:

3

I've got a framed environment of the memoir class with content like this:

\begin{framed}
\subsection{Article 1}
Content of Article 1
\subsection{Article 2}
Content: Article 2
\end{framed}

This renders in the following way:

._________________.
|                 |   <-- superfluous whitespace
| Article 1       |
| Content of Art- |
| icle 1          |
|                 |
| Article 2       |
| Content: Artic- |
| le 2            |
.-----------------.

The \subsection{} is introducing the whitespace preceding itself, which I'd prefer not to be there inside this framed environment, though I do want such whitespace in regular text (i.e. outside the framed environment) and for subsections-after-the first one.

When inside the framed environment, I'd like to have formatting essentially like this:

._________________.
| Article 1       |
| Content of Art- |
| icle 1          |
|                 |
| Article 2       |
| Content: Artic- |
| le 2            |
.-----------------.

Any thoughts or suggestions as to how one may achieve this modification to headings at the beginning of the framed environment would be much appreciated.


Edit: Based on mkluwe's comments, I've rooted out the \subsection command in memoir.cls:

 3314 \newcommand{\subsection}{%
 3315   \subsechook%
 3316   \@startsection{subsection}{2}%  level 2
 3317       {\subsecindent}%            heading indent
 3318       {\beforesubsecskip}%        skip before the heading
 3319       {\aftersubsecskip}%         skip after the heading
 3320       {\normalfont\subsecheadstyle}} % font
 3321 \newcommand{\subsechook}{}
 3322 \newcommand{\setsubsechook}[1]{\renewcommand{\subsechook}{#1}}
 3323 \newlength{\subsecindent}
 3324 \newcommand{\setsubsecindent}[1]{\setlength{\subsecindent}{#1}}
 3325   \setsubsecindent{\z@}
 3326 \newskip\beforesubsecskip
 3327 \newcommand{\setbeforesubsecskip}[1]{\setlength{\beforesubsecskip}{#1}}
 3328   \setbeforesubsecskip{-3.25ex \@plus -1ex \@minus -.2ex}
 3329 \newskip\aftersubsecskip
 3330 \newcommand{\setaftersubsecskip}[1]{\setlength{\aftersubsecskip}{#1}}
 3331   \setaftersubsecskip{1.5ex \@plus .2ex}

So a corollary to my question above would seem to be: How can one refine this subsection command such that e.g. if it's the first element in an environment (such as the framed environment) its \beforesubsecskip is very small?


Thank you for reading.

Sincerely,

Brian

+1  A: 

I don't know this environment, but in the documentation I find:

\FrameHeightAdjust: macro; height of frame above baseline at top of page

You might try diddling that...

dmckee
@dmckee: thanks for the reply; I've tried tinkering with `\FrameHeightAdjust`, but it didn't seem to have any effect. I think the problem is in the `\subsection` command, as in my edit.
Brian M. Hunt
+1  A: 

As a quick and dirty solution I copied the definition of the \subsection command from article.cls and deleted the vertical skip:

\documentclass{article}
\usepackage{framed}
\makeatletter
\newcommand\subsectionx{\@startsection{subsection}{2}{\z@}%
                                     {0ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\large\bfseries}}
\makeatother
\begin{document}
\begin{framed}
\subsectionx{Article 1}
Content of Article 1
\subsection{Article 2}
Content: Article 2
\end{framed}
\end{document}
mkluwe
@mkluwe: Thanks for the answer. The subsection is definitely where the action is. However I don't want to delete the vertical skip for all subsections -- just subsections that start new environments.
Brian M. Hunt
Yes, did you try to run my example? I provides a new command \subsectionx which eliminates the vertical skip. This is used to start the first subsection in the framed environment. I assume you overlooked the appended 'x' (I should have made it more palpable).
mkluwe
+1  A: 

If it happens infrequently enough you could just use a vspace command as first entry inside each frame. You could even create a new frame environment to do it automatically. In any case you would need to tweak the vspace to take away the right amount of padding. As you want, the new environment below will remove padding for first subsection entry but not for the subsequent ones:

\newenvironment{subsectframe}{\begin{framed}\vspace{-1.0\baselineskip}}{\end{framed}}

\begin{document}

\begin{subsectframe}
\subsection{Article 1}
Content of Article 1
\subsection{Article 2}
Content: Article 2
\end{subsectframe}

\end{document}

I do understand that the problem is "with the subsection". However I think fixing it by creating a new environment is going to be cleaner solution than trying to alter the subsection command so it intelligently avoids adding space depending on where it is.

Herbert Sitz
@Herbert: Thank you. That's exactly what I was looking for. I didn't know `\vspace` could have negative attributes!
Brian M. Hunt
@Herbert: One caveat, which I can work around, is that when the `framed` environment begins with something other than a `\subsection` (or equivalent, with leading space), the text starts on top of the frame line -- i.e. the `\vspace{-1.0\baselineskip}` eats too much space. Ideally that `\vspace` would only occur when the frame starts with a `\subsection` or equivalent.
Brian M. Hunt
@Brian: Yes, the new environment presupposes that you have some knowledge of what's going to be in it. So if it's a frame that's going to start with a subsection you use the new 'subsecframe' and if it's not going to have initial subsection then just use a regular 'framed' environment. If you edit things a lot and things often change within a frame (i.e, change from having initial subsection to not), then it might be better not to bother with a new frame environment at all, just use vspace commands as necessary.
Herbert Sitz