Hot answers tagged

97

Let's first identify what we're referring to when we use the term "table". The typical table environment is a float, and can contain anything: a paragraph of text, an image, or even a tabular. Working with the latter - a tabular - and how to adjust it is what is discussed here. The discussion also applies to array structures since they provide an math ...


53

The caption package provides a width parameter than can be set for each figure individually. This way you can adjust the width to suit the width of your figure: \documentclass{article} \usepackage[margin=1in]{geometry}% Just for this example \usepackage{lipsum}% Just for this example \usepackage{graphicx,caption} \begin{document} \begin{figure}[t] \...


31

in tikz any coordinate of any path command is determined for the infinitely thin lines. the real lines lie over them so that their centers matches. line width of real lines is accessible with length \pgflinewidth. knowing it, it is simple to correct size of some elementary shapes as are rectangles, squares and circles with considering line widths. for ...


29

I think you have two good choices and a (likely) dreadful choice: Use a tabular* environment, Use a tabularx environment (or its close cousin, tabulary) Use the basic tabular environment and scale it up (or down) using \resizebox. The results are as follows (the first horizontal line is there just to illustrate the width of the text block; the bodies of ...


28

Something like this? \documentclass{article} \newlength\stextwidth \newcommand\makesamewidth[3][c]{% \settowidth{\stextwidth}{#2}% \makebox[\stextwidth][#1]{#3}% } \begin{document} \fbox{\makesamewidth[c]{text to set width}{new text}} \end{document} If the order of arguments is important you can use xparse: \documentclass{article} \usepackage{xparse}...


26

Update Use \arrayrulewidth from the preamble and place it before the desired table using a group to keep the change to \arrayrulewidth local: \documentclass[11pt]{article} \usepackage{array} \begin{document} \begin{tabular}{|l|l|l|l|} \hline & & & \\ \hline & & & \\ \hline & & & \\ \hline & & &...


19

If you don't mind putting the variable-width text into a node, then it is relatively easy. You can adjust the spacing to your liking further. \documentclass{article} \usepackage{tikz,fancyhdr,lipsum} \usetikzlibrary{calc} \usepackage[includeheadfoot,margin=0.8cm]{geometry} \fancyhf{} \pagestyle{fancy} \rfoot{1 of 10} \definecolor{shadeleft}{RGB}{222,...


18

calc provides \widthof{<stuff>}: \documentclass{article} \usepackage{calc} \setlength{\parindent}{0pt}% Just for this example \begin{document} Here is some text that is lengthy.\par \makebox[\widthof{Here is some text that is lengthy}][l]{Left}\par \makebox[\widthof{Here is some text that is lengthy}][c]{Centre}\par \makebox[\widthof{Here is some text ...


15

If you want to change the behaviour of \underbrace globally you could say \documentclass{article} \usepackage{amsmath} \makeatletter \let\ams@underbrace=\underbrace \def\underbrace#1_#2{% \setbox0=\hbox{$\displaystyle#1$}% \ams@underbrace{#1}_{\parbox[t]{\the\wd0}{#2}}% } \makeatother \begin{document} $\underbrace{f(x) = a^2 + 2ab + b^2}_{This is some ...


15

Just let the graphicx package have its way: \documentclass{article} \usepackage{graphicx} \usepackage[showframe]{geometry} %just to visualise the boarder \begin{document} \noindent\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{example-image-golden} \newpage \noindent\includegraphics[width=\textwidth,height=\textheight,...


14

\documentclass{article} \usepackage{lipsum}% http://ctan.org/pkg/lipsum \parindent0pt \parskip\bigskipamount \makeatletter \def\newparshape{\parshape\@npshape0{}} \def\@npshape#1#2#3{\ifx\\#3\expandafter\@@@npshape\else\expandafter\@@npshape\fi {#1}{#2}{#3}} \def\@@npshape#1#2#3#4#5{% \ifnum#3>\z@\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi ...


14

The basic answer is that (in classic TeX, at least, not sure about luatex) is that you can't. For any symbol \foo you can use \setbox\mybox{\kern..\raisebox{..}{\foo}\kern..} \ht\mybox=.. \wd\mybox==.. \dp\mybox=.. To make a box of any required size with the glyph at any position within that bounding box, so \usebox\mybox will do more or less the ...


14

You have several options here: you can use the top, left, bottom, right keys (and perhaps also boxsep) to control the space between text and frame on each of the sides or you could use the size key to get some predefined sizes (the accepted values minimal, tight, fbox, small, title, and normal and their effect are illustrated in my example code): \...


13

docs for http://mirror.unl.edu/ctan/macros/latex/contrib/tabu/tabu.pdf are found here. after reviewing them. ive come up with a solution. \documentclass{report} \usepackage{longtable,tabu} \begin{document} \begin{longtabu} to \textwidth { X[1,c] X[1,c] X[1,c] X[10,l]} \hline \hline \textbf{Time End of Step} & \textbf{Step} ...


12

Warsaw internally uses the shadow outer theme which, in its turn, uses the split outer theme which defines the headline (when the compress option is not activated) as \defbeamertemplate*{headline}{split theme} {% \leavevmode% \@tempdimb=2.4375ex% \ifnum\beamer@subsectionmax<\beamer@sectionmax% \multiply\@tempdimb by\beamer@sectionmax% \else% ...


12

Two possible ways to choose from. The first is making the whole subfigure a bit smaller, which will also make the figure a little bit smaller. If that is undesired, just make the caption width a bit smaller. No matter which way you choose, it looks kind of odd without centering the picture. \documentclass{article} \usepackage{graphicx} \usepackage{...


12

The frame is put outside of the listings. Therefore xleftmargin and xrightmargin can be used to leave room for the frame. The default for framesep is 3pt and the default for framerule is 0.4pt. Result: \documentclass[]{article} \usepackage{listings} \lstset{ basicstyle=\ttfamily\footnotesize, frame=single, % adds a frame around the code ...


12

Informally, length calculation are done using factor multiplication as there is no division notation. Since any division can be represented as some multiplication, this shouldn't be a problem. So, .5\textwidth refers to half (1/2) of \textwidth, while 2\wd0 refers to twice the width of box 0. In your case it suffices to use \includegraphics[width=0.3333\...


11

The varwidth package's similarly-named varwidth environment provides this functionality by default, setting a box of "natural width" if the width is smaller than what is specified: \documentclass[10pt,a4paper]{article} \usepackage{varwidth}% http://ctan.org/pkg/varwidth %\encadrer: \newcommand{\encadrer}[1]{{% \centering \fbox{% \begin{varwidth}{\...


11

Instead of using a predetermined width, one can measure the width using a savebox and put the caption inside a minipage. \documentclass{article} \usepackage{graphicx} \usepackage{blindtext} \begin{document} \begin{figure} \sbox0{\includegraphics{example-image}}% measure width \centering \begin{minipage}{\wd0} \usebox0 \caption{\blindtext} \end{minipage}...


11

In this code I define a \parunderbrace command, with two arguments, which adjusts automatically to the width of the formula: \documentclass{article} \usepackage{mathtools} \usepackage{ragged2e} \newlength\ubwidth \newcommand\parunderbrace[2]{\settowidth\ubwidth{$#1$}\underbrace{#1}_{\parbox{\ubwidth}{\scriptsize\RaggedRight#2}}} \begin{document} \[ \...


11

You can use a \makebox to create a box as wide as the slash: Code: \documentclass{article} \usepackage{amsmath} \usepackage{calc} \newcommand*{\mycdot}{\makebox[\widthof{/}]{$\cdot$}} \newcommand*{\myslash}{\makebox[\widthof{${}\cdot{}$}]{{}/{}}} \begin{document}\noindent \verb|\cdot| same width as slash: \begin{align*} x &= a \mycdot a \\ x &= a /...


11

If your image is wider than \textwidth you'll have to work on it to adjust it to desired width. This solution won't change any image dimension (width, height, font size) unless you do it. Another solution could be to use standalone class. In this case, you'll work on an independent file to produce the desired image and, later on, include it in your text ...


11

If you specify both height and width keys, and specify keepaspectratio then the values are taken as upper bounds and the image is scaled so that both height and width fit within the specified areas, so you need something like \includegraphics[width=\textwidth, height=.75\textheight,keepaspectratio]{..} if the caption takes .25\textheight


11

From this excellent macro of Thomas F. Sturm: ....fit the width...., here there is my adapt answer: \documentclass[11pt]{article} \usepackage[many]{tcolorbox} \tcbset{longtitle/.style={% title={#1}, before upper={\begin{tabular}{@{}l@{}l}\phantom{#1}\\[\the\dimexpr-\ht\strutbox-\dp\strutbox]}, after upper={\end{tabular}}} } \begin{document} \begin{...


10

It works fine for me, but you need to zoom in a lot to see the difference between very thin and thin (the latter is the default line width). Try setting the straight line to ultra thick to verify that it's working. To change the axis line style, use axis line style = ultra thick.


10

\makebox puts its contents into a box, whose dimensions are available as \width, \height, \depth inside the optional arguments of \makebox: \documentclass{article} \newcommand*{\minwidthbox}[2]{% \makebox[{\ifdim#2<\width\width\else#2\fi}]{#1}% } \begin{document} \noindent [\minwidthbox{i}{2em}]\\\relax [\minwidthbox{WXYZ}{2em}] \end{document} ...


10

You can use fit library to compute node's height. But with fitting nodes, it's better to add its contents with the label option. Following code defines a barstyle style with two arguments, the first one is the original node which is used to get its height while the second is the node contents. \documentclass{article} \usepackage{tikz} \usepackage{varwidth} ...


Only top voted, non community-wiki answers of a minimum length are eligible