TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have long equation, Ax=b that I want to put a frame around. I can't use mdframed since I need to also compile this with tex4ht, which still does not support mdframed. So I use this trick setup:

\fbox{
\noindent\begin{minipage}{\linewidth}
\scriptsize
\[
\begin{bmatrix}
...
\end{bmatrix}
\]
\end{minipage}
}
\normalsize

This works, but the problem with the above, is that the fbox does not fit the whole minipage. Here is screen

Mathematica graphics

Without minipage and no frame, here is how it looks like:

Mathematica graphics

My question is: How can one automatically have fbox fit the minipage content? The solution has to also compile with not errors with tex4ht. Is there a way to tell Latex to shift the page margin to the left more, just in the minipage? i.e. make the minipage uses custom geometry? I tried this

\fbox{
\noindent\begin{minipage}{\linewidth}
\newgeometry{left=.1in,right=.1in,top=1in,bottom=1in}
\scriptsize
....

But it made things worst. I do get these messages from lualatex, but this is because the equations are too wide. But they are still in the page.

Overfull \hbox (31.09998pt too wide) in paragraph at lines 49--51
[][][] 

Here is the MWE. Sorry for large equation size, but this is the example am working on.

\documentclass[11pt]{report}%
\usepackage{amsmath,mathtools}
\usepackage[paperheight=11in,paperwidth=8.5in,top=.7in,bottom=.7in, 
      left=1.2in, right=.8in]{geometry}
\begin{document}

Therefore, the $Ax=b$ system to solve is%

\fbox{
\noindent\begin{minipage}{\linewidth}
\scriptsize
\[%
\begin{bmatrix}
7 & \left(  -4-\frac{1}{2}h^{3}\right)   & 1 & 0 & \cdots & 0 & 0 & 0\\
\left(  -4+\frac{1}{2}h^{3}\right)   & 6 & \left(  -4-\frac{1}{2}h^{3}\right)
& 1 & 0 & \cdots & 0 & 0\\
1 & \left(  -4+\frac{1}{2}h^{3}\right)   & 6 & \left(  -4-\frac{1}{2}%
h^{3}\right)   & 1 & 0 & \cdots & 0\\
0 & 1 & \left(  -4+\frac{1}{2}h^{3}\right)   & 6 & \left(  -4+\frac{1}{2}%
h^{3}\right)   & 1 & 0 & \cdots\\
0 & 0 & \left(  -4+\frac{1}{2}h^{3}\right)   & 6 & \left(  -4+\frac{1}{2}%
h^{3}\right)   & 1 & 0 & \cdots\\
&  &  &  &  &  &  & \\
&  &  &  &  &  &  & \\
&  &  &  &  &  &  &
\end{bmatrix}%
\begin{bmatrix}
y_{1}\\
y_{2}\\
y_{3}\\
y_{4}\\
\vdots\\
y_{N-2}\\
y_{N-1}\\
y_{N}%
\end{bmatrix}
=%
\begin{bmatrix}
h^{4}e^{h}-2hy_{0}^{\prime}+y_{0}\left(  4-\frac{1}{2}h^{3}\right)  \\
h^{4}e^{2h}-y_{0}\\
h^{4}e^{3h}\\
h^{4}e^{4h}\\
\vdots\\
\\
\\
\end{bmatrix}
\]
\end{minipage}
}
\normalsize

Therefore ...

\end{document}

compiled using lualatex foo.tex TL 2015

share|improve this question
up vote 3 down vote accepted

You have to avoid minipage, that constrains the size.

\documentclass[11pt]{report}
\usepackage{amsmath,mathtools}
\usepackage[
  letterpaper,
  top=.7in, bottom=.7in, 
  left=1.2in, right=.8in
]{geometry}

\DeclarePairedDelimiter{\paren}{(}{)}

\begin{document}

Therefore, the $Ax=b$ system to solve is
\[
\makebox[\textwidth]{\fbox{%
  \scriptsize$
  \begin{bmatrix}
  7 & \paren*{-4-\frac{1}{2}h^{3}}   & 1 & 0 & \cdots & 0 & 0 & 0\\
  \paren*{-4+\frac{1}{2}h^{3}}   & 6 & \paren*{-4-\frac{1}{2}h^{3}}
  & 1 & 0 & \cdots & 0 & 0\\
  1 & \paren*{-4+\frac{1}{2}h^{3}}   & 6 & \paren*{-4-\frac{1}{2}h^{3}}   & 1 & 0 & \cdots & 0\\
  0 & 1 & \paren*{-4+\frac{1}{2}h^{3}}   & 6 & \paren*{-4+\frac{1}{2}h^{3}}   & 1 & 0 & \cdots\\
  0 & 0 & \paren*{-4+\frac{1}{2}h^{3}}   & 6 & \paren*{-4+\frac{1}{2}h^{3}}   & 1 & 0 & \cdots\\
  &  &  &  &  &  &  & \\
  &  &  &  &  &  &  & \\
  &  &  &  &  &  &  &
  \end{bmatrix}
  \begin{bmatrix}
  y_{1}\\
  y_{2}\\
  y_{3}\\
  y_{4}\\
  \vdots\\
  y_{N-2}\\
  y_{N-1}\\
  y_{N}
  \end{bmatrix}
  =
  \begin{bmatrix}
  h^{4}e^{h}-2hy_{0}^{\prime}+y_{0}\paren*{4-\frac{1}{2}h^{3}}  \\
  h^{4}e^{2h}-y_{0}\\
  h^{4}e^{3h}\\
  h^{4}e^{4h}\\
  \vdots\\
  \\
  \\
  \end{bmatrix}
$}}
\]
Therefore ...

\end{document}

enter image description here

share|improve this answer

You have

\fbox{
\noindent\begin{minipage}{\linewidth}
\end{minipage}
}

\fbox like \mbox is a horizontal mode construct so \noindent there is not doing anything.

So you have on a line that is \linewidth wide

  • A paragraph indent
  • A vertical rule of width \fboxrule
  • Padding of width \fboxsep
  • one inter-word space from the white space after {
  • A minipage of width \linewidth
  • One inter-word space from the white space before }
  • Padding of width fboxsep
  • A vertical rule of width \fboxrule
  • \parfillskip glue, natural length 0pt most likely.

That does not fit.

You want

\noindent
\fbox{%
\begin{minipage}{\dimexpr\linewidth-2\fboxrule-2\fboxsep}
\end{minipage}%
}
share|improve this answer
    
the actual question is not clear, but it seems the OP has an issue with the fact that the actual contents of the minipage do not fit in \linewidth. He probably misunderstands the meaning of the minipage first argument. – jfbu Feb 13 at 11:10
    
Thanks. But on the question of \noindent it did change things. In one of my trials. I had this: \fbox{ \noindent\begin{minipage}{\paperwidth}... and now removing the \noindent made things worst, it shifted the minipage. But this only when using \paperwidth. If I had \fbox{\begin{minipage}{\linewidth}... then, you are correct, now it has no effect. Removing it changes nothing. But before I was using \paperwidth, that is why I had it there. (too many variables, and too many options to tweak. Latex is hard! – Nasser Feb 13 at 11:31
    
@jfbu yes I spotted that as well but thought best to answer the general question in the title rather than the specifics about the particular content of this box. – David Carlisle Feb 13 at 11:31
    
@Nasser no \noindent inside the \fbox has no effect it does not make it worse or better (and obviously it isn't affected by \paperwidth or \linewidth). tweaking latex isn't hard if you just follow some basic principles. – David Carlisle Feb 13 at 11:33

Resize it to \linewidth:

\documentclass[11pt]{report}
\usepackage{mathtools}
\usepackage[
  letterpaper,
  top=.7in, bottom=.7in, 
  left=1.2in, right=.8in
]{geometry}    
\DeclarePairedDelimiter{\paren}{(}{)}

\begin{document}

Therefore, the $Ax=b$ system to solve is
\[
\fbox{\resizebox{\dimexpr\linewidth-2\fboxrule-2\fboxsep}{!}{$
        \begin{bmatrix}
        7 & \paren*{-4-\frac{1}{2}h^{3}}   & 1 & 0 & \cdots & 0 & 0 & 0\\
        \paren*{-4+\frac{1}{2}h^{3}}   & 6 & \paren*{-4-\frac{1}{2}h^{3}}
        & 1 & 0 & \cdots & 0 & 0\\
        1 & \paren*{-4+\frac{1}{2}h^{3}}   & 6 & \paren*{-4-\frac{1}{2}h^{3}}   & 1 & 
        0 & \cdots & 0\\
        0 & 1 & \paren*{-4+\frac{1}{2}h^{3}}   & 6 & \paren*{-4+\frac{1}{2}h^{3}}   & 
        1 & 0 & \cdots\\
        0 & 0 & \paren*{-4+\frac{1}{2}h^{3}}   & 6 & \paren*{-4+\frac{1}{2}h^{3}}   & 
        1 & 0 & \cdots\\
        &  &  &  &  &  &  & \\
        &  &  &  &  &  &  & \\
        &  &  &  &  &  &  &
        \end{bmatrix}
        \begin{bmatrix}
        y_{1}\\
        y_{2}\\
        y_{3}\\
        y_{4}\\
        \vdots\\
        y_{N-2}\\
        y_{N-1}\\
        y_{N}
        \end{bmatrix}
        =
        \begin{bmatrix}
        h^{4}e^{h}-2hy_{0}^{\prime}+y_{0}\paren*{4-\frac{1}{2}h^{3}}  \\
        h^{4}e^{2h}-y_{0}\\
        h^{4}e^{3h}\\
        h^{4}e^{4h}\\
        \vdots\\
        \\
        \\
        \end{bmatrix}
        $}}
\]
Therefore \ldots\hrulefill

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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