[Tex/LaTex] align margin note to vertical center of text block or environment, with optional bar

marginparvertical alignment

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[letterpaper,hmargin=1.5in,vmargin=0.8in,nohead,nofoot,showframe]{geometry}
\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:

non-examples

here are some possibly related questions:

Best Answer

you can hide the frame using hideframe as option.

code:

\documentclass{article}
\usepackage[letterpaper,hmargin=1.5in,vmargin=0.8in,nohead,nofoot,hideframe]{geometry}
\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}

enter image description here

Related Question