The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

20

You can use \boxed command from amsmath package \documentclass{article} \usepackage{amsmath} \begin{document} \begin{equation*} X=\boxed{X_1 X_2}\quad \boxed{X_3 X_4}\cdots\boxed{X_5 X_6} \end{equation*} \end{document} To add colors and labels below boxes \documentclass{article} \usepackage{amsmath,tcolorbox} \tcbuselibrary{theorems,skins} \...


16

I think it would probably be useful to understand how TeX normally inserts vertical space between lines/boxes. This will make it clear why this spacing is different when you wrap your paragraphs in a \vbox, as in your MWE. A method to achieve identical spacing with and without boxes can be found at the bottom this answer. About \baselineskip and \lineskip ...


15

Short answer: as far as I know, a box directly produced with the \hbox command can't have a negative height, but a box produced with the \vbox command can. A horizontal box can have a negative height if it is stored in a box register, say \box0, and one executes an assignment of the form \ht0=〈dimen〉 with a negative 〈dimen〉. Example of a \vbox with negative ...


14

\documentclass{article} \usepackage{xcolor,stackengine} \newcommand\palbox[2]{{\sffamily\fboxsep=5pt\relax\fboxrule=1pt\relax\footnotesize% \fcolorbox{gray!50}{gray!10}{% \stackengine{8pt}{% \colorbox[RGB]{#1}{\rule{60pt}{0pt}\rule{0pt}{60pt}}% }{% \color{black!60}\stackengine{12pt}{\##2}{\saycolors{#1}}{U}{l}{F}{F}{S}% }{U}{l}{F}{F}...


10

The obvious problem is that D is wider than A. We can get a true square around capital letters by using the height as width: \documentclass{article} \newcommand{\squarecap}[1]{\fbox{\makebox[\height]{#1}}} \begin{document} \squarecap{A}\par \squarecap{B}\par \squarecap{C}\par \squarecap{D}\par \squarecap{E}\par \squarecap{M}\par \end{document} The ...


9

Yes, it is possible with TikZ. You can do this in two ways: by including the code directly in the text. by creating a LaTeX command named autour which contains the TikZ code. Here is an example of two possibilities that have different parameters in order to visually show their effects. \documentclass{article} \usepackage{tikz} \newcommand{\autour}[1]{\...


9

You can use \eqmakebox[<tag>][<align>]{<stuff>} to have all <stuff> with the same <tag> be set <align>ed in a box of maximum width. Below I've played around with those so you can see what the effect is: \documentclass{extarticle} \usepackage[UTF8]{inputenc} \usepackage{siunitx,eqparbox} % https://tex.stackexchange.com/...


9

A TikZ solution that includes the image file inside a tikzpicture and draws a square and cross relative to the coordinates of the image: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node[inner sep=0] (image) at (0,0) {\includegraphics[width=0.5\textwidth]{example-image}}; \draw[red,ultra thick] (image.south east) --...


9

That is sesamanuel class % !TeX TS-program = xelatex \documentclass{sesamanuel} \begin{document} \themaF \chapter{title} \end{document}


9

With a tabularx: \documentclass{article} \usepackage{geometry} \usepackage{array} \usepackage{makecell} \usepackage{tabularx} \begin{document} \noindent\begin{tabularx}{\linewidth}{|p{.1cm}cp{.3cm}|p{.3cm}Xp{.1cm}|} \hline &\rule{0pt}{1.4cm}\makecell{\textbf{TRƯỜNG ĐHSP TP.HCM}\\ \textbf{Khoa Toán - Tin học}\\ \rule{1.7in}{1pt}\\ \textbf{Đề ...


8

All graphics are written to the PDF with a scale factor. When you specify a size the package just converts it to an appropriate scale factor. You can make \Gscale@box remember that scale factor for you (source). You can use the same \thelastscalefactor as many times as you need: \documentclass{article} \usepackage{graphicx} \makeatletter \let\ORG@Gscale@...


8

You can have a horizontal box with negative height, as the dimensions of box registers are assignable, but when constructing a box with \hbox the maximum of 0pt and the positive heights of the content is used. \tracingonline1 \setbox0=\hbox{a} \showbox0 \ht0=-20pt \showbox0 \setbox2\hbox{\box0} \showbox2 \bye Produces \hbox(4.30554+0.0)x5.00002 ...


8

A \vcenter is handled as a \vbox except that a vcent atom is wrapped around the construct which finally means that the resulting box is adjusted so its height+depth are centred on the math axis. However as Udo pointed out in comments the finer points of appendix G in the TeXBook do mean that there are some differences in the way \scriptspace is handled. \...


7

Here's a solution using tikz. It uses expl3 to automatically calculate the hex value. \documentclass{article} \usepackage[margin=2cm]{geometry} \usepackage{xparse} \usepackage{tikz} \usetikzlibrary{positioning, backgrounds, shadows} \ExplSyntaxOn \cs_new:Nn \__criw_rgbtohex:n { \clist_set:Nx \l_tmpa_clist {#1} \clist_map_inline:Nn \l_tmpa_clist ...


7

geometry changes the page size unless you use options to prevent that, \documentclass{article} \showthe\textwidth \usepackage{geometry}% works when commented out \showthe\textwidth \newcommand{\block}{\rule{0.5\textwidth}{1pt}\allowbreak} \parindent=0pt \begin{document} \block \block \block \block \end{document} You see the same without geometry but with ...


6

With the 2018/12/01 release of LaTeX something has changed about \leavevmode. The command didn't change, but a few others were modified. In particular \thinspace \negthinspace \enspace \finph@nt (used by \phantom, \hphantom and \vphantom) \finsm@sh (used by \smash) \big, \Big, \bigg, \Bigg were modified to add \leavevmode@ifvmode, which is a sort of “...


6

as supplement to @Marjin answer (+1), a little bit shorter code ... \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node (image) [inner sep=0] {\includegraphics[width=0.5\textwidth]{example-image}}; \draw[red,ultra thick] (image.south west) -- (image.north east) (image.north west) -- (image.south ...


6

You can use \smash{\vrule}, but you have to specify the height and depth. \documentclass{article} \begin{document} \sbox0{\fbox{some text more text}}% \fbox{some text \smash{\vrule height\ht0 depth\dp0} more text} \sbox0{\fbox{some text more deep text}}% \fbox{some text \smash{\vrule height\ht0 depth\dp0} more deep text} \sbox0{\fbox{some text more $\int$ ...


6

You can keep the width= on the graphics and trim/clip separately so not affecting the scaling, see the last example here: \documentclass{article} \usepackage{graphicx,adjustbox} \begin{document} \includegraphics[width=.4\textwidth]{example-image} \bigskip \includegraphics[clip,trim=1cm .5cm .7cm .1cm, width=.4\textwidth]{example-image} \bigskip \...


6

According to TeX, 0.5\textwidth+0.5\textwidth may not be equal to \textwidth. When geometry sets the text width to 430.00462pt, this is precisely what happens. The sum of the widths of two rules falls 1sp short of the textwidth and TeX tries to stick another rule in the first line, having no stretchability available. However, you can do more accurate ...


6

The code for that specific part of The TeXbook reads: For example, you can say \begintt \vbox{\hbox{Two lines}\hbox{of type.}} \endtt and \TeX\ will convert this into \begindisplay% \setbox0=\vbox{\hbox{\demobox{Two lines}}\hbox{\demobox{of type.}}} $\vcenter{\hbox{\makelightbox\kern-\wd0\box0}}$\qquad i.e.,\qquad$\vcenter{\vbox{\hbox{Two lines}\hbox{of ...


5

As marmot suggests, I'd wrap this in a table. In fact, to ensure consistent formatting I would wrap everything into a nice little macro so that you can write your table as \ImageTable{ {example-image-a}{Resilience, in that broken nodes ...}, {example-image-b}{Spontaneity, a feature empowered...}, {example-image-c}{Decentralization, in the ...


5

Not directly but using etex you can measure where the glue went and make a box of the same size on the next run: \documentclass{article} \makeatletter \def\zz#1{\pdfsavepos\write\@auxout{\gdef\string#1{\the\pdflastypos}}} \makeatother \begin{document} \section{ZZZZ} zzzz \[z=z\] zzz \noindent\zz{\zzA}\begin{picture}(0,0) \put(0,0){% \fbox{\begin{...


5

\settominwidth uses internally a tabular. This means that you are doing \begin{tabular}{@{}l@{}} {\color{red} One \\ Two} \end{tabular} And this doesn't work as cell are groups.


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