5

I'm using an align-environment(employing the empheq package) with a surrounding \fbox for showing a set of formulas. Now I'm trying to draw a horizontal line under both "Part 1" and "Part 2" which ranges to the borders of the \fbox. I tried a simple \hline but of course the boundaries are unmatched.

\documentclass{article}
\usepackage{empheq}
\begin{document}

\begin{empheq}[box=\fbox]{flalign*}
  & \text{Part 1} & \\
  & x=x & \text{(A1)} \\
  & \text{Part 2} & \\
  & y=y & \text{(K)}
\end{empheq}

\end{document}
1

Based on your comments in the original question regarding the formatting of your equation box and assuming you are not bound to the empheq package you could try the following -- even though the the line does not span the whole length of the box (but, the result looks quite convincing).

output

\documentclass{article}
\usepackage{titlesec}
  \titleformat{\section}
    {\normalfont\Large\bfseries}{\thesection}{1em}{}[{\titlerule[.8pt]}]
\usepackage[fleqn]{amsmath}
\usepackage{framed}

\begin{document}
\begin{framed}
  \section*{Part 1}
  \begin{equation*}
    x=x \tag{A1}
  \end{equation*}
  \section*{Part 2}
  \begin{equation*}
    y=y \tag{K}
  \end{equation*}
\end{framed}
\end{document}
| improve this answer | |
3

I don't think you want a rule below “Part 1” and “Part 2”, but between the two parts. Anyway, I provide both solutions.

\documentclass{article}
\usepackage{array}

\begin{document}

\[
\renewcommand{\arraystretch}{1.2}
\begin{tabular*}{\displaywidth}{
  |@{\extracolsep{\fill}\hspace{\tabcolsep}}
  l >{$\displaystyle}r<{$} @{\extracolsep{0pt}} >{$\displaystyle{}}l<{$}
  @{\extracolsep{\fill}} r|
}
\hline
\textit{Part 1} &&&\\
\hline
(A1) & x&=a & \\
\hline
\textit{Part 2} &&&\\
\hline
(K)  & y&=c+d & \\
\hline
\end{tabular*}
\]

\[
\renewcommand{\arraystretch}{1.2}
\begin{tabular*}{\displaywidth}{
  |@{\extracolsep{\fill}\hspace{\tabcolsep}}
  l >{$\displaystyle}r<{$} @{\extracolsep{0pt}} >{$\displaystyle{}}l<{$}
  @{\extracolsep{\fill}} r|
}
\hline
\textit{Part 1} &&&\\
(A1) & x&=a & \\
\hline
\textit{Part 2} &&&\\
(K)  & y&=c+d & \\
\hline
\end{tabular*}
\]

\end{document}

enter image description here

If you want the tags on the right, here it is:

\documentclass{article}
\usepackage{array}

\begin{document}

\[
\renewcommand{\arraystretch}{1.2}
\begin{tabular*}{\displaywidth}{
  |@{\extracolsep{\fill}\hspace{\tabcolsep}}
  l >{$\displaystyle}r<{$} @{\extracolsep{0pt}} >{$\displaystyle{}}l<{$}
  @{\extracolsep{\fill}} r|
}
\hline
\textit{Part 1} &&&\\
\hline
& x&=a & (A1)\\
\hline
\textit{Part 2} &&&\\
\hline
& y&=c+d & (K)\\
\hline
\end{tabular*}
\]

\[
\renewcommand{\arraystretch}{1.2}
\begin{tabular*}{\displaywidth}{
  |@{\extracolsep{\fill}\hspace{\tabcolsep}}
  l >{$\displaystyle}r<{$} @{\extracolsep{0pt}} >{$\displaystyle{}}l<{$}
  @{\extracolsep{\fill}} r|
}
\hline
\textit{Part 1} &&&\\
& x&=a & (A1)\\
\hline
\textit{Part 2} &&&\\
& y&=c+d & (K)\\
\hline
\end{tabular*}
\]

\end{document}

enter image description here

A different implementation:

\documentclass{article}
\usepackage{empheq}

\begin{document}

\begingroup\setlength{\fboxsep}{0pt}
\begin{empheq}[box=\fbox]{flalign*}
\noalign{\vspace{3pt}}
 \, & \text{Part 1} & \\\
 \, & x=x & \text{(A1)}\, \\\noalign{\vspace{3pt}\hrule\vspace{3pt}}
 \, & \text{Part 2} & \\
 \, & y=y & \text{(K)\strut} \,
\end{empheq}
\endgroup

\end{document}

but, honestly, I wouldn't use such an approach. Too much space between the elements.

enter image description here

| improve this answer | |
  • is there a simple command mod from which i can use \hline inside my original code – blub Dec 25 '16 at 20:56
  • @zzuussee I added a possibility, but I don't like at all such an approach. – egreg Dec 25 '16 at 21:09
1

Here is a solution, if I've well understood what you want:

\documentclass{article}
\usepackage{empheq}
\newcommand\eqsection[1]{%
\shortintertext{\rlap{#1}\hspace{-\fontdimen2\font}\rule[-1ex]{\dimexpr\linewidth + 2\fontdimen2\font}{0.4pt}}}

\begin{document}

\begin{empheq}[box=\fbox]{flalign*}
  \eqsection{Part 1}
  & x=x & \text{(A1)} \\
  \eqsection{Part 2}
  & y=y & \text{(K)}
\end{empheq}

\end{document}

enter image description here

| improve this answer | |
1

The margins that are not covered by \hrule comes from the inner margin of the \fbox with dimension \fboxsep.

The following command \empheqsepline puts the rule in an \hbox. Then it is easier to make the rule longer and let it extend to the left and right. \nointerlineskip removes vertical space introduced by \hbox. Before and after the rule \kern commands add some space. The example uses \fboxsep, but it can be changed to fit the needs.

The example file first uses the line to separate the parts. The second case puts the line under the part titles and uses space to separate the parts.

\documentclass{article}
\usepackage{empheq}

\newcommand*{\empheqsepline}{%
  \noalign{%
    % Space above the rule
    \kern\fboxsep
    % The rule
    \nointerlineskip
    \hbox to 0pt{%
      \kern-\fboxsep
      \vrule width\dimexpr\displaywidth+2\fboxsep height \fboxrule
      \hss
    }%
    \nointerlineskip
    % Space below the rule
    \kern\fboxsep
  }%
}

\begin{document}
\begin{empheq}[box=\fbox]{flalign*}
  & \text{Part 1} & \\
  & x=x & \text{(A1)} \\
  \empheqsepline
  & \text{Part 2} & \\
  & y=y & \text{(K)}
\end{empheq}

\begin{empheq}[box=\fbox]{flalign*}
  & \text{Part 1} & \\
  \empheqsepline
  & x=x & \text{(A1)} \\[2ex]
  & \text{Part 2} & \\
  \empheqsepline
  & y=y & \text{(K)}
\end{empheq}
\end{document}

Result

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.