# align margin note to vertical center of text block or environment, with optional bar

Here is what I wish to achieve:

• section title as usual
• (optional) subsection in left-margin, aligned to top of its contents
• group of text/theorem/etc blocks within subsection
• margin note or label aligned to vertical center of individual blocks
• vertical rule along block

Ideally, in case of page break in a block, the margin note would be vertically positioned where it would be if the page were not broken, or else if the block is split equally across pages, the first line after the break

In reality the blocks are actually sub-proofs of a larger proof I would be writing for a school assignment. Perhaps this could further be implemented as some kind of theorem environment with labels in the margins?

Here's my MWE:

\documentclass{article}
\usepackage[small]{titlesec}
\titleformat{\subsection}[leftmargin]{\raggedleft\bfseries}{}{0pt}{}
\titlespacing*{\subsection}{1.5in}{*2.5}{*2}
\usepackage{lipsum}
\usepackage{mdframed}
\newmdenv[topline=false, leftline=false, bottomline=false,%
linewidth=1pt, innerleftmargin=0pt, rightmargin=-1pt,%
innerrightmargin=5pt, skipabove=8pt, skipbelow=8pt]{rightbar}

\begin{document}
\section*{A1}
\subsection*{not good$\uparrow \downarrow$}
\begin{minipage}[c]{\linewidth}
\begin{rightbar}
\lipsum[1]
\end{rightbar}
\end{minipage}\marginpar{good}

\vspace{2ex}
\noindent
\begin{minipage}[c]{\linewidth}
\begin{rightbar}
\lipsum[1]
\end{rightbar}
\end{minipage}\marginpar{good}

\subsection*{not good $\rightarrow$}
\begin{minipage}[t]{\linewidth}
\begin{rightbar}
\lipsum[1]
\end{rightbar}
\end{minipage}\marginpar{$\downarrow$not good}

\subsection*{good}
\lipsum[1]
\marginpar{$\uparrow$ not good}
\vspace{3ex}
\end{document}


here's what that looks like:

here are some possibly related questions:

• Do the "subsections" actually have to be \subsections, which is to say, do they have to be auto-numberable, capable of appearing in the table of contents? Or merely top-left margin entities associated with the paragraph? Also, what are the requirements for page breaking? Making the centered-right marginpar work across a page boundary, in tandem with the associated paragraph, would be very difficult to accomplish. – Steven B. Segletes Mar 17 '14 at 0:47

you can hide the frame using hideframe as option.

code:

\documentclass{article}
\usepackage[small]{titlesec}
\titleformat{\subsection}[leftmargin]{\raggedleft\bfseries}{}{0pt}{}
\titlespacing*{\subsection}{1.5in}{*2.5}{*1}
\usepackage{lipsum}
\usepackage{mdframed}
\newmdenv[topline=false, leftline=false, bottomline=false,%
linewidth=1pt, innerleftmargin=0pt, rightmargin= 4pt,%
innerrightmargin=5pt, skipabove=8pt, skipbelow=8pt]{rightbar}
\begin{document}
\section*{A1}
\subsection*{not good$\uparrow \downarrow$}
\begin{minipage}[c]{\linewidth}
\begin{rightbar}

\lipsum[1]
\end{rightbar}
\end{minipage}\marginpar{good}

\vspace{2ex}
\noindent
\begin{minipage}[c]{\linewidth}
\begin{rightbar}
\lipsum[1]
\end{rightbar}
\end{minipage}\marginpar{good}

\subsection*{not good $\rightarrow$}
\begin{minipage}[c]{\linewidth}
\begin{rightbar}
\lipsum[1]
\end{rightbar}
\end{minipage}\marginpar{$\downarrow$not good}

\subsection*{good}
\lipsum[1]
\marginpar{$\uparrow$ not good}
\vspace{3ex}

%\end{minipage}
\end{document}