2

I am trying to frame a text with \fbox and make auto-newline before or in the text. Currently, my formulas are out of the margin when they are too long (Sometimes there is text, not only formulas). border around text

Part of my code :

\documentclass[a4paper]{article}
\usepackage[a4paper,top=0.1cm,bottom=0.1cm,left=0.1cm,right=1cm,marginparwidth=0.1cm]{geometry}
\usepackage{amsmath}

%boxx
\newcommand{\boxx}[1]{\fbox{#1}}
%matrix
\newcommand{\mtx}[2]{\ensuremath{{\binom{#1}{#2}}}}

\begin{document}
...
\boxx{$\mtx{n}{k} = \mtx n{n-k}$} 
\boxx{$\mtx{n}{k} = \frac nk \mtx{n-1}{k-1}$} 
\boxx{$\mtx{n}{k} = \mtx{n-1}{k-1} + \mtx{n-1}k$} 
\boxx{$\mtx{i}{k}\mtx{k}{j} = \mtx{i}{j} \mtx{i-j}{k-j}$} 
\boxx{$(x+y)^n = \sum^n_{k=0} \mtx nk x^{n-k}y^k$} 
\boxx{$\sum^m_{n=k}\mtx nk = \mtx{m+1}{k+1}$} 
\boxx{$(k_1,k_2,\dots,k_t) = \frac{n!}{k_1!k_2!\dots k_n!}$} 
\boxx{$(x_1+x_2+\dots+x_t)^n = \sum_{k_1+k2+\dots+k_t=n}(k_1,\dots,k_t) x_1^{k_1} , x_2^{k_2}, \dots, x_t^{k_t}$} 
\boxx{$(1+x)^n = \sum^n_{p=0}\mtx np x^n$}
\boxx{$(1+x)^{-n} = (\frac{1}{1-x})^n = \sum^n_{p=0}\mtx {n+q-1}q x^q$} 
...
\end{document}
4
  • Try tcolorbox package
    – user31729
    Aug 31, 2017 at 17:28
  • 2
    welcome to tex.se. to help you we should see your code (in form of small, complete document, beginning with\documentclass{...} and ending with \end{document}. otherwise we can only guessing or give some general advice.
    – Zarko
    Aug 31, 2017 at 17:28
  • Welcome to TeX.SX!. Please don't just show parts of your code, but take the time and create a complete MWE!
    – Skillmon
    Aug 31, 2017 at 17:37
  • This is the main code, putting everything is not necessary because it is composed only of \boxx
    – Rod
    Aug 31, 2017 at 17:47

1 Answer 1

0

I added \noindent\raggedright at the beginning of the document. The \noindent to prevent indentation on the 1st line, the \raggedright is useful when typesetting large horizontal blocks, which otherwise tend not to align with margins (if you did not want \raggedright, \sloppy might be an alternative, in which case the gaps would be distributed between boxes rather than at the end of the line).

No additional breaking mechanism is needed, because you provide an implied space between your \fboxes by putting one per line. If that space were absent, you would need an \allowbreak between \fboxes to permit the line break between boxes.

\documentclass[a4paper]{article}
\usepackage[a4paper,top=0.1cm,bottom=0.1cm,left=0.1cm,right=1cm,marginparwidth=0.1cm]{geometry}
\usepackage{amsmath}

%boxx
\newcommand{\boxx}[1]{\fbox{#1}}
%matrix
\newcommand{\mtx}[2]{\ensuremath{{\binom{#1}{#2}}}}

\begin{document}
\noindent\raggedright...
\boxx{$\mtx{n}{k} = \mtx n{n-k}$} 
\boxx{$\mtx{n}{k} = \frac nk \mtx{n-1}{k-1}$} 
\boxx{$\mtx{n}{k} = \mtx{n-1}{k-1} + \mtx{n-1}k$} 
\boxx{$\mtx{i}{k}\mtx{k}{j} = \mtx{i}{j} \mtx{i-j}{k-j}$} 
\boxx{$(x+y)^n = \sum^n_{k=0} \mtx nk x^{n-k}y^k$} 
\boxx{$\sum^m_{n=k}\mtx nk = \mtx{m+1}{k+1}$} 
\boxx{$(k_1,k_2,\dots,k_t) = \frac{n!}{k_1!k_2!\dots k_n!}$} 
\boxx{$(x_1+x_2+\dots+x_t)^n = \sum_{k_1+k2+\dots+k_t=n}(k_1,\dots,k_t) x_1^{k_1} , x_2^{k_2}, \dots, x_t^{k_t}$} 
\boxx{$(1+x)^n = \sum^n_{p=0}\mtx np x^n$}
\boxx{$(1+x)^{-n} = (\frac{1}{1-x})^n = \sum^n_{p=0}\mtx {n+q-1}q x^q$} 
...
\end{document}

enter image description here

Here is what it looks like with \raggedright replaced by \sloppy:

enter image description here

And here is what it would look like with \raggedright but \boxx defined as \newcommand{\boxx}[1]{\fbox{#1}\allowbreak\ignorespaces}

enter image description here

1
  • Wow. awesome. This is exactly what I needed in detail! Thanks a lot
    – Rod
    Aug 31, 2017 at 17:52

You must log in to answer this question.

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