2

I use mdframed boxes with maths. As my work is about geometry, I end up having vertical 3d vectors, which take up quite some vertical space. This is leading to non-uniform vertical spacing:

enter image description here

MWE:

\documentclass[
10pt, 
a4paper, 
oneside, 
headinclude,
footinclude, 
BCOR5mm, 
titlepage
]{scrartcl}

\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsmath}
\usepackage{pgf,tikz}
\usepackage{mathrsfs}
\usepackage{mathtools}
\usepackage{float}
\usepackage{bm}
\usepackage{pstricks-add}
\usepackage{commath}

\mdfdefinestyle{Beispiel}{%
linecolor=blue,
outerlinewidth=2pt,
roundcorner=20pt,
innertopmargin=\baselineskip,
innerbottommargin=\baselineskip,
innerrightmargin=20pt,
innerleftmargin=20pt,
backgroundcolor=gray!10!white
}

\begin{document}

\begin{mdframed}[style=Beispiel]
\begin{center}
    {\textbf{Beispiel}}
\end{center}%
\bigskip
\noindent Zeigen Sie, dass die Gerade $g:\vec{x} = \left( \begin{smallmatrix} 7 \\ 3 \end{smallmatrix} \right) + t \cdot  \left( \begin{smallmatrix} 1 \\ -1 \end{smallmatrix} \right)  $ 
den Kreis\newline$c: \left( \vec{x}- \left( \begin{smallmatrix}2 \\ 1 \end{smallmatrix} \right) \right)^2 = 25$ schneidet und bestimmen Sie die Koordinaten der Schnittpunkte.
    \begin{alignat*}{2} 
    \text{Einsetzen} \qquad &\left( \left( \begin{smallmatrix} 7 \\ 3 \end{smallmatrix} \right) + t \cdot \left( \begin{smallmatrix} 1 \\ -1 \end{smallmatrix} \right) - \left( \begin{smallmatrix}2 \\ 1 \end{smallmatrix} \right) \right)^2 = 25 \\
    \text{Vereinfachen} \qquad & \left( \left( \begin{smallmatrix} 5 \\ 2 \end{smallmatrix} \right) + t \cdot \left( \begin{smallmatrix} 1 \\ -1 \end{smallmatrix} \right) \right)^2 = 25 \\  
        \text{Potenz aufl{\"o}sen} \qquad & (5+t)^2 + (2-t)^2 = 25 \\
     & t_{1} = -1 \quad t_{2} = -2
    \end{alignat*}%
    \newline
    Damit haben $g$ und $c$ zwei Schnittpunkte. Um die Punkte zu bestimmen, substituiert
    man beide L\"{o}sungen in die Geradengleichung und erh\"{a}lt dann die Ortsvektoren
    \begin{equation*}
    \vec{P} = \left( \begin{smallmatrix} 6 \\ 4 \end{smallmatrix} \right) \quad \vec{Q} = \left( \begin{smallmatrix} 5 \\ 5 \end{smallmatrix} \right)
    \end{equation*}
    beziehungsweise die Punkte
    \begin{equation*}
        P(6|4), Q(5|5)
    \end{equation*}
\end{mdframed}


\end{document}
2
  • This has nothing to do with mdframed. If you put large objects in your lines tex will insert space to avoid that they overlap. You could e.g. enlarge the baselineskip. And use less \left/right, your parentheses are imho too large. May 25, 2017 at 13:14
  • @UlrikeFischer I need the \left because otherwise the compiler will start to do weird things with the exponent after the bracket and it starts to look silly. I do not have much experience with vertical spacing, so I'd be very happy if someone could provide a solution with uniform spacing. The spacing may differ compared to the rest of the document (i.e. be much bigger) but should be consistent in the md-environment.
    – Narusan
    May 25, 2017 at 13:17

2 Answers 2

1

You could use the \smallpmatrix(*) environment, since you load mathtools(needless to load amsmath in this case, and replace the remaining \left … \right pairs with \bigl … \bigr. I also loaded setspace to increase \baselineskip inside mdframed, replaced | with \mid for a better spacing, and loaded inputencwith option [utf8] and fontenc with option [T1] to typeset umlauts directly from the keyboard.

\documentclass[
10pt,
a4paper,
oneside,
headinclude,
footinclude,
BCOR=5mm,
titlepage
]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[framemethod=TikZ]{mdframed}
\usepackage{pgf,tikz}
\usepackage{mathrsfs}
\usepackage{mathtools}
\usepackage{float}
\usepackage{bm}
\usepackage{pstricks-add}
\usepackage{commath}

\mdfdefinestyle{Beispiel}{%
linecolor=blue,
outerlinewidth=2pt,
roundcorner=20pt,
innertopmargin=\baselineskip,
innerbottommargin=\baselineskip,
innerrightmargin=20pt,
innerleftmargin=20pt,
backgroundcolor=gray!10!white
}
\usepackage{setspace}

\begin{document}

\begin{mdframed}[style=Beispiel]
  \setstretch{1.1}
  \begin{center}
    {\textbf{Beispiel}}
  \end{center}%
  \bigskip
  \noindent Zeigen Sie, dass die Gerade $g:\vec{x} = \begin{psmallmatrix}7 \\ 3 \end{psmallmatrix} + t · \begin{psmallmatrix*}[r]1 \\ -1 \end{psmallmatrix*}$
  den Kreis\newline $c: \bigl( \vec{x}- \begin{psmallmatrix}2 \\ 1 \end{psmallmatrix}\bigr)² = 25$ schneidet und bestimmen Sie die Koordinaten der Schnittpunkte.
  \begin{alignat*}{2}
    \text{Einsetzen} \qquad & \bigl(\begin{psmallmatrix} 7 \\ 3 \end{psmallmatrix}+ t · \begin{psmallmatrix*}[r]1 \\ -1 \end{psmallmatrix*}- \begin{psmallmatrix}2 \\ 1 \end{psmallmatrix}\bigr)² = 25 \\
    \text{Vereinfachen} \qquad & \bigl(\begin{psmallmatrix} 5 \\ 2 \end{psmallmatrix} + t · \begin{psmallmatrix*}[r]1 \\ -1 \end{psmallmatrix*}\bigr)² = 25 \\[0.6ex]
    \text{Potenz auflösen} \qquad & (5+t)² + (2-t)² = 25 \\[0.5ex]
                                  & t_{1} = -1 \quad t_{2} = -2
  \end{alignat*}%
  \newline
  Damit haben $g$ und $c$ zwei Schnittpunkte. Um die Punkte zu bestimmen, substituiert
  man beide L\"{o}sungen in die Geradengleichung und erh\"{a}lt dann die Ortsvektoren
  \begin{gather*}
    \vec{P} = \begin{psmallmatrix}6 \\ 4 \end{psmallmatrix} \quad \vec{Q} = \begin{psmallmatrix}5 \\ 5 \end{psmallmatrix}\\
    \shortintertext{beziehungsweise die Punkte}
    P(6∣4), Q(5\mid5)
  \end{gather*}
\end{mdframed}

\end{document} 

enter image description here

3
  • I don't have Umlauts on my keyboard, so it's quicker to just type *"{a}*. This turned out pretty good. The spacing between "Vereinfachen" and "Potenz auflösen" is still not quite perfect, but it looks a lot better. Thank you!
    – Narusan
    May 25, 2017 at 14:42
  • 1
    @Narusan: I've added a manual correction to the spacing. Please see if it's OK now. Concerning the umlauts, you may have bad hyphenation, as ä is not considered then as a single character. It would be better to ask your editor to use "{a} (or whatever) as a shortcut for the real ä.
    – Bernard
    May 25, 2017 at 15:27
  • The spacing is great now! Thank you so much!
    – Narusan
    May 25, 2017 at 15:55
2

I did something to handle each cited instance of undesirable spacing. For the first case, I merely smashed the exponent, as in ^{\smash{2}}, which was causing the larger gap atop the equation.

In the second instance, I converted the alignat* into an \alignCenterstack, which produces lines with equal baselineskips (set here to 20pt.) Along the way, I also had to change the tabstackengine end-of-line from \\ to \#, so as not to get confused over the smallmatrix separators.

\documentclass[
10pt, 
a4paper, 
oneside, 
headinclude,
footinclude, 
BCOR5mm, 
titlepage
]{scrartcl}

\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsmath}
\usepackage{pgf,tikz}
\usepackage{mathrsfs}
\usepackage{mathtools}
\usepackage{float}
\usepackage{bm}
\usepackage{pstricks-add}
\usepackage{commath}

\mdfdefinestyle{Beispiel}{%
linecolor=blue,
outerlinewidth=2pt,
roundcorner=20pt,
innertopmargin=\baselineskip,
innerbottommargin=\baselineskip,
innerrightmargin=20pt,
innerleftmargin=20pt,
backgroundcolor=gray!10!white
}
\usepackage{tabstackengine}
\TABstackMath
\setstackEOL{\#}
\setstackgap{L}{20pt}
\begin{document}

\begin{mdframed}[style=Beispiel]
\begin{center}
    {\textbf{Beispiel}}
\end{center}%
\bigskip
\noindent Zeigen Sie, dass die Gerade $g:\vec{x} = \left( \begin{smallmatrix} 7 \\ 3 \end{smallmatrix} \right) + t \cdot  \left( \begin{smallmatrix} 1 \\ -1 \end{smallmatrix} \right)  $ 
den Kreis\newline$c: \left( \vec{x}- \left( \begin{smallmatrix}2 \\ 1 \end{smallmatrix} \right) \right)^{\smash{2}} = 25$ schneidet und bestimmen Sie die Koordinaten der Schnittpunkte.\smallskip

    \alignCenterstack{ 
    \text{Einsetzen} \qquad & \left( \left( \begin{smallmatrix} 7 \\ 3 \end{smallmatrix} \right) + t \cdot \left( \begin{smallmatrix} 1 \\ -1 \end{smallmatrix} \right) - \left( \begin{smallmatrix}2 \\ 1 \end{smallmatrix} \right) \right)^2 = 25 \#
    \text{Vereinfachen} \qquad & \left( \left( \begin{smallmatrix} 5 \\ 2 \end{smallmatrix} \right) + t \cdot \left( \begin{smallmatrix} 1 \\ -1 \end{smallmatrix} \right) \right)^2 = 25 \#  
        \text{Potenz aufl{\"o}sen} \qquad & (5+t)^2 + (2-t)^2 = 25 \\
     & t_{1} = -1 \quad t_{2} = -2
    }\bigskip

    Damit haben $g$ und $c$ zwei Schnittpunkte. Um die Punkte zu bestimmen, substituiert
    man beide L\"{o}sungen in die Geradengleichung und erh\"{a}lt dann die Ortsvektoren
    \begin{equation*}
    \vec{P} = \left( \begin{smallmatrix} 6 \\ 4 \end{smallmatrix} \right) \quad \vec{Q} = \left( \begin{smallmatrix} 5 \\ 5 \end{smallmatrix} \right)
    \end{equation*}
    beziehungsweise die Punkte
    \begin{equation*}
        P(6|4), Q(5|5)
    \end{equation*}
\end{mdframed}


\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .