The left margin is too wide if I set 1.5\textwidth
:
\begin{document}
\noindent\begin{minipage}{1.5\textwidth}
test
\end{minipage}
\end{document}
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityPut it inside a centered box
\documentclass{article}
\begin{document}
\noindent\hrulefill\par
\noindent\makebox[\textwidth][c]{%
\begin{minipage}{1.5\textwidth}
\hrulefill\par
\end{minipage}}
\end{document}
\linewidth
should be used instead of \textwidth
per this post about the difference between these two
May 18, 2011 at 3:38
\textwidth
and it is difficult to say without context what it is used for. If you are looking for a fixed global width it is \textwidth
. If the widths need to change with local column, environment of box width, then use \linewidth
May 18, 2011 at 4:02
A simple way to do this is to use \centerline{..}
around the minipage
. (This does not allow for verbatim or similar special content, but there is a \Centerline
variant from the realboxes
package, which does!)
I would add some small or medium vertical skip before and after this minipage
to get decent vertical spacing.
\documentclass{article}
\usepackage{lipsum}% dummy text
\begin{document}
\lipsum[1]
\par\smallskip\noindent
\centerline{\begin{minipage}{1.5\textwidth}
\lipsum[2]
\end{minipage}}
\par\smallskip
\lipsum[3]
\end{document}
Another easy way is to use the adjustbox
environment from the package with the same name. It provides the keys minipage=<minipage args>
, center
(=<length>
, normally \linewidth
) and also margin
(=<left/right> <top/bottom>
, and more).
\documentclass{article}
\usepackage{adjustbox}
\usepackage{lipsum}% dummy text
\begin{document}
\lipsum[1]
\begin{adjustbox}{minipage=1.5\textwidth,margin=0pt \smallskipamount,center}
\lipsum[2]
\end{adjustbox}
\lipsum[3]
\end{document}
Compare the similar question and answers at How can I center a too wide table?.
l2tabu
it stated that it should not be used to center text, because it e.g. can cause issues when used inside lists. I think it is fine for this case, i.e. a large block in a paragraph of it's own.
Apr 13, 2012 at 13:19
I was putting parcolumns and verbatim blocks inside my minipage which was causing problems. I found this rather simple solution quite effective:
\noindent\hspace{0.15\linewidth}\begin{minipage}{0.7\linewidth}
...
\end{minipage}
This creates a smaller minipage and centres with a positive hspace. Using the rule hspace = (1\linewidth - minipage_width) / 2
will also work for values larger than \linewidth
and produce a negative hspace:
\newlength{\myminipagewidth}
\newlength{\myminipagecentering}
\setlength{\myminipagewidth}{1.5\linewidth} %change this
\setlength{\myminipagecentering}{(\linewidth-\myminipagewidth)/2}
\noindent\hspace{\myminipagecentering}\begin{minipage}{\myminipagewidth}
...
\end{minipage}
(sub \linewidth
with \textwidth
when needed)
Very simple, enclose that minipage in center using \begin{center} and \end{center} as shown below:
\begin{center}
\noindent\begin{minipage}{1.5\textwidth}
text
\end{minipage}
\end{center}
center
environment will not center content that is wider than the textwidth. \documentclass{article} \usepackage{lipsum} \begin{document} \lipsum[1] \begin{center} \begin{minipage}{1.5\textwidth} \lipsum[4] \end{minipage} \end{center} \lipsum[4] \end{document}
will result in i.stack.imgur.com/ZdtEI.png
Mar 22, 2020 at 11:22