It is possible to overlap and left-align text by using \rlap{A}BCD; however, how to overlap A in the middle (exactly centered) of BCD?
- 317
5 Answers
The default is exactly centered overlap, but fine adjustments may be made with the optional argument.
\documentclass{article}
\usepackage{stackengine}
\newcommand\clap[3][0pt]{\stackengine{0pt}{#3}{\kern#1#2}{O}{c}{F}{F}{L}}
\begin{document}
\clap{A}{BCD}
\clap[6pt]{A}{BCD}
\clap[-6pt]{A}{BCD}
\end{document}
- 237,551
I use \makebox in combination with the \widthof command from the calc package.
\documentclass{article}
\usepackage{calc}
\begin{document}
\begin{itemize}
\item ABCD
\item \makebox[0ex][l]{BCD}A
\item \makebox[1ex][l]{BCD}A
\item \makebox[2ex][l]{BCD}A
\item \makebox[3ex][l]{BCD}A
\item \makebox[4ex][l]{BCD}A
\end{itemize}
\begin{itemize}
\item ABCD
\item \makebox[\widthof{BCD}/2-\widthof{A}/2][l]{BCD}A
\item \frame{\makebox[\widthof{BCD}/2-\widthof{A}/2][l]{BCD}}A %for illustration
\end{itemize}
\end{document}
With \makebox[\widthof{BCD}/2-\widthof{A}/2][l]{BCD}A you get:
Side note: Remove the items that include \makebox and you get a MWE.
- 22,451
-
Sorry for the misleading word usage. I mean how to put A in the center (exactly middle) of BCD. – Kevin Dong Feb 13 '18 at 17:42
-
-
-
@KevinDong Then consider accepting the answer and the case is closed. – Dr. Manuel Kuehner Feb 13 '18 at 17:51
It's easy with \ooalign:
\documentclass{article}
\newcommand{\overlap}[2]{%
\leavevmode\begingroup
\vphantom{#1#2}%
\ooalign{\hfil#1\hfil\cr\hfil#2\hfil\cr}%
\endgroup
}
\begin{document}
\overlap{A}{BCD}
\textsf{\overlap{I}{XXX}}
\end{document}
- 1,121,712
-
-
+1. Better, of course. I would rename
\overlapto something like\myOverlapor\EgregOverlapor\CustomOverlapto avoid the impression that it is a "standard" command. And I would have guessed that an x is symmetrical :). – Dr. Manuel Kuehner Feb 13 '18 at 17:55 -
This tex command solution is cool, but
\ooalignis slightly less intuitive for beginners. – Kevin Dong Feb 13 '18 at 17:55 -
1@Dr.ManuelKuehner Do you do that with every custom macro you define? Must destroy auto-complete in your editor. – cfr Feb 14 '18 at 03:22
-
Maybe I don't define as many custom macros as you :). I am not a programmer and maybe therefore I am a bit conservative in this regard. I get confused by there little things. It's just an idea and not criticism. I do not understand the argument with the autocomplete. I use Texmaker and do not add custom commands to autocomplete if that's what you mean. Thanks for replying. – Dr. Manuel Kuehner Feb 14 '18 at 07:13
Your main concern here is to place A and BCD in a box that has the same size/width. That way you can overlay them and achieve the alignment you're after.
To obtain similarly-sized boxes (width-wise), you can use eqparbox's \eqmakebox[<tag>][<align>]{<stuff>}:
\documentclass{article}
\usepackage{eqparbox}
\begin{document}
BCD
\makebox[0pt][l]{\eqmakebox[ABCD]{A}}% or \leavevmode\rlap{\eqmakebox[ABCD]{A}}%
\eqmakebox[ABCD]{BCD}
\end{document}
\eqmakebox places <stuff> with the same <tag> in a box that has the maximum width of all <stuff>. Individual box <align>ment can be specified (left, center/default, right).
- 603,163
-
Since
eqparboxuses a\label-\ref-like system, you'll have to compile twice with every change in the<stuff>that influences the maximum width associated with that<tag>. – Werner Feb 13 '18 at 18:14 -
+1 Never crossed
eqparboxbefore (at least I don't remember). Will look into it. So far I normally use\makeboxand\phantommanually etc. Do you know ifScott Pakinis also a user here`He maintains a lot of packages on CTAN. – Dr. Manuel Kuehner Feb 13 '18 at 19:13 -
1@Dr.ManuelKuehner: I haven't seen him around, no. You'll find him on comp.text.tex though. – Werner Feb 13 '18 at 19:18
The \stackinset command is perhaps simpler to use. Nor correction was necessary for this example, so I left the corresponding arguments empty:
\documentclass[12pt]{article}
\usepackage{stackengine}
\usepackage[svgnames]{xcolor}
\begin{document}
\Large\stackinset{c}{}{c}{}{\color{Tomato}A}{BCD}
\end{document}
- 271,350
-
2
-
1
-
-
2@Dr.ManuelKuehner: I'd prefer by far ‘Cuisse de Nymphe Émue’, but there's no such colour in the color-by-names of
xcolor. – Bernard Feb 13 '18 at 19:00






\ooalignon the site – egreg Feb 13 '18 at 17:21\makeboxwith a width of zero can help. And a MWE is still possible. – Dr. Manuel Kuehner Feb 13 '18 at 17:22\makeboxtakes the length input rather than the string BCD. – Kevin Dong Feb 13 '18 at 17:25\usepackage{stackengine}...\stackengine{0pt}{BCD}{\kern2pt A}{O}{l}{F}{F}{L}where 2pt is altered to fit your need. – Steven B. Segletes Feb 13 '18 at 17:39\ooalignfrom @egreg: https://tex.stackexchange.com/questions/22371 – Dr. Manuel Kuehner Feb 13 '18 at 17:39