Set size of colorbox for a single character
my question is simple (or not) I want to set the size of the colorbox command or fcolorbox command for a single character. The problem is the next:

As seen in the image, the height and width are different for different characters, but what I want is that the size is the same for all characters. The package that I use is xcolorand the code I used to generate the box character is
noindentcolorbox{black!85}{textcolor{white}{i}}
My objective is a box with individually centred character. The background of the box in black color and text in white. Also would be nice if it is a enumitem and the items are in a black box
color boxes characters size
add a comment |
my question is simple (or not) I want to set the size of the colorbox command or fcolorbox command for a single character. The problem is the next:

As seen in the image, the height and width are different for different characters, but what I want is that the size is the same for all characters. The package that I use is xcolorand the code I used to generate the box character is
noindentcolorbox{black!85}{textcolor{white}{i}}
My objective is a box with individually centred character. The background of the box in black color and text in white. Also would be nice if it is a enumitem and the items are in a black box
color boxes characters size
add a comment |
my question is simple (or not) I want to set the size of the colorbox command or fcolorbox command for a single character. The problem is the next:

As seen in the image, the height and width are different for different characters, but what I want is that the size is the same for all characters. The package that I use is xcolorand the code I used to generate the box character is
noindentcolorbox{black!85}{textcolor{white}{i}}
My objective is a box with individually centred character. The background of the box in black color and text in white. Also would be nice if it is a enumitem and the items are in a black box
color boxes characters size
my question is simple (or not) I want to set the size of the colorbox command or fcolorbox command for a single character. The problem is the next:

As seen in the image, the height and width are different for different characters, but what I want is that the size is the same for all characters. The package that I use is xcolorand the code I used to generate the box character is
noindentcolorbox{black!85}{textcolor{white}{i}}
My objective is a box with individually centred character. The background of the box in black color and text in white. Also would be nice if it is a enumitem and the items are in a black box
color boxes characters size
color boxes characters size
edited Dec 27 '18 at 15:10
Martin Scharrer♦
199k45632815
199k45632815
asked Apr 27 '14 at 0:00
Kiyoshi
5541820
5541820
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
colorbox{black!85}{makebox[2em]{struttextcolor{white}{a}}}
or any other width that you want.
Or as if indicated in comments you want vertical as well as horizontal centering
colorbox{black!85}{makebox(12,12){textcolor{white}{a}}}
where the size of the box, 12, is given in picture environment units (pt by default)
David your solution is a very good and simple solution, but I want a smaller height.
– Kiyoshi
Apr 27 '14 at 9:35
@Kiyoshi replacestrutbyrule[1pt]{0pt}{5pt}replacing 1 and 5 for whatever depth and height you want
– David Carlisle
Apr 27 '14 at 9:52
If possible to create acolorboxwith the same width and height for all character but the characters in center of a box?
– Kiyoshi
Apr 27 '14 at 10:17
@Kiyoshi makebox centres by default, so the characters should be horizontally centred, and by adjusting the height and depth you use in the strut you can make the baseline be wherever you want or do you want an A to be lower than an a so they are individually centred rather than being on the same baseline?
– David Carlisle
Apr 27 '14 at 10:20
Exactly, I want a individually centred.
– Kiyoshi
Apr 27 '14 at 10:30
|
show 1 more comment
With tikz:
documentclass{article}
usepackage{tikz}
newcommandcoloredtext[2]{tikz[baseline=(char.base)]node[minimum width=2em,text height=1.5ex, text depth=0.1ex,fill=black!85,text=white,#1](char){#2};}%
begin{document}
noindent
foreach x in {a,b,...,z}{%
coloredtext{x},
}
noindent
foreach x in {A,B,...,Z}{%
coloredtext[minimum width=2.55em]{x}
}%
end{document}

I can control perfectly the width and the height, if is possible to center the character in a box that would be amazing ;)
– Kiyoshi
Apr 27 '14 at 10:00
@Kiyoshi They are already centered horizontally by default.
– user11232
Apr 27 '14 at 12:53
add a comment |
I would suggest using the eqparbox package, if you want to have equal and minimal widths of the boxes (two runs are required):
documentclass[11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{fourier}
usepackage{eqparbox}
usepackage[x11names]{xcolor}
begin{document}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}I}}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}W}}
end{document}

If you want the coloured boxes to have the same heights, while keeping the natural width of the widest, you can adjust the height in two ways:
- Either insert a
vphantom{highest entry}as an argument toeqmakebox. Of course, it's up to you to decide which will be the highest entry. One may turn it into an optional argument of a macro. - Or insert an invisible rule that lets you predefine the height of the box.
I give an example of both, the second solution with predefined height equal to 1 cm. This can make possible fancy effects.
documentclass[11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{fourier}
usepackage{eqparbox}
usepackage[x11names]{xcolor}
begin{document}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}I}}
enspace
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}W}}
enspace
colorbox{DeepPink4}{eqmakebox[L]{vphantom{Largebfseries W}footnotesizebfseriescolor{AntiqueWhite1}W}}
enspace\
colorbox{AntiqueWhite1}{eqmakebox[L]{rule{0pt}{dimexpr 1cm-2fboxseprelax}Largebfseriescolor{DeepPink4}W}}
enspace
colorbox{AntiqueWhite1}{eqmakebox[L]{rule{0pt}{dimexpr 1cm-2fboxseprelax}footnotesizebfseriescolor{DeepPink4}i}}
enspace\
colorbox{AntiqueWhite1}{eqmakebox[L]{rule[-0.4cm]{0pt}{dimexpr 1cm-2fboxseprelax}Largebfseriescolor{DeepPink4}W}}
enspace
colorbox{AntiqueWhite1}{eqmakebox[L]{rule[-0.4cm]{0pt}{dimexpr 1cm-2fboxseprelax}footnotesizebfseriescolor{DeepPink4}i}}
end{document}

The problem witheqparboxis when I adjust the box to a character normal size the height is not equal.
– Kiyoshi
Apr 27 '14 at 9:46
@ Kiyoshi: Do you mean that if your letters have different sizes, hence differnt heights, the height of the coloured boxes will be different, and you'd like it to be the same?
– Bernard
Apr 27 '14 at 10:55
@ Bernard: Same size and centred
– Kiyoshi
Apr 27 '14 at 10:58
@Kiyoshi: Updated my answer. I added two solutions to the height problem.
– Bernard
Apr 27 '14 at 12:14
add a comment |
The first optional argument is the textcolor and the second is the background color.
documentclass{article}
usepackage[x11names]{xcolor}
makeatletter
defCbox{@ifnextchar[Cbox@i{Cbox@i[white]}}
defCbox@i[#1]{@ifnextchar[{Cbox@ii[#1]}{Cbox@ii[#1][black]}}
defCbox@ii[#1][#2]#3{colorbox{#2}{makebox[1em]{struttextcolor{#1}{#3}}}}
makeatother
begin{document}
Cbox{I} Cbox[yellow]{g} Cbox[AntiqueWhite1][DeepPink4]{W}
end{document}

Nice solution, but I want a smaller height box.
– Kiyoshi
Apr 27 '14 at 9:52
add a comment |
Here a solution with the adjustbox package. You can create the centered box using the center=<width> key. Adding strut gives you the same height and depths independent of the character size. If you use htstrutbox+dpstrutbox as the width you will get a nice square.
documentclass{article}
usepackage{xcolor}
usepackage{adjustbox}
newcommandblackboxchar[1]{noindent
adjustbox{center=htstrutbox+dpstrutbox,frame,bgcolor=black!85}{color{white}strut #1}}
begin{document}
begin{itemize}
item[blackboxchar{i}] text text text text
item[blackboxchar{a}] text text text text
item[blackboxchar{m}] text text text text
end{itemize}
end{document}

add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f173695%2fset-size-of-colorbox-for-a-single-character%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
colorbox{black!85}{makebox[2em]{struttextcolor{white}{a}}}
or any other width that you want.
Or as if indicated in comments you want vertical as well as horizontal centering
colorbox{black!85}{makebox(12,12){textcolor{white}{a}}}
where the size of the box, 12, is given in picture environment units (pt by default)
David your solution is a very good and simple solution, but I want a smaller height.
– Kiyoshi
Apr 27 '14 at 9:35
@Kiyoshi replacestrutbyrule[1pt]{0pt}{5pt}replacing 1 and 5 for whatever depth and height you want
– David Carlisle
Apr 27 '14 at 9:52
If possible to create acolorboxwith the same width and height for all character but the characters in center of a box?
– Kiyoshi
Apr 27 '14 at 10:17
@Kiyoshi makebox centres by default, so the characters should be horizontally centred, and by adjusting the height and depth you use in the strut you can make the baseline be wherever you want or do you want an A to be lower than an a so they are individually centred rather than being on the same baseline?
– David Carlisle
Apr 27 '14 at 10:20
Exactly, I want a individually centred.
– Kiyoshi
Apr 27 '14 at 10:30
|
show 1 more comment
colorbox{black!85}{makebox[2em]{struttextcolor{white}{a}}}
or any other width that you want.
Or as if indicated in comments you want vertical as well as horizontal centering
colorbox{black!85}{makebox(12,12){textcolor{white}{a}}}
where the size of the box, 12, is given in picture environment units (pt by default)
David your solution is a very good and simple solution, but I want a smaller height.
– Kiyoshi
Apr 27 '14 at 9:35
@Kiyoshi replacestrutbyrule[1pt]{0pt}{5pt}replacing 1 and 5 for whatever depth and height you want
– David Carlisle
Apr 27 '14 at 9:52
If possible to create acolorboxwith the same width and height for all character but the characters in center of a box?
– Kiyoshi
Apr 27 '14 at 10:17
@Kiyoshi makebox centres by default, so the characters should be horizontally centred, and by adjusting the height and depth you use in the strut you can make the baseline be wherever you want or do you want an A to be lower than an a so they are individually centred rather than being on the same baseline?
– David Carlisle
Apr 27 '14 at 10:20
Exactly, I want a individually centred.
– Kiyoshi
Apr 27 '14 at 10:30
|
show 1 more comment
colorbox{black!85}{makebox[2em]{struttextcolor{white}{a}}}
or any other width that you want.
Or as if indicated in comments you want vertical as well as horizontal centering
colorbox{black!85}{makebox(12,12){textcolor{white}{a}}}
where the size of the box, 12, is given in picture environment units (pt by default)
colorbox{black!85}{makebox[2em]{struttextcolor{white}{a}}}
or any other width that you want.
Or as if indicated in comments you want vertical as well as horizontal centering
colorbox{black!85}{makebox(12,12){textcolor{white}{a}}}
where the size of the box, 12, is given in picture environment units (pt by default)
edited Apr 27 '14 at 11:04
answered Apr 27 '14 at 0:04
David Carlisle
483k4011151856
483k4011151856
David your solution is a very good and simple solution, but I want a smaller height.
– Kiyoshi
Apr 27 '14 at 9:35
@Kiyoshi replacestrutbyrule[1pt]{0pt}{5pt}replacing 1 and 5 for whatever depth and height you want
– David Carlisle
Apr 27 '14 at 9:52
If possible to create acolorboxwith the same width and height for all character but the characters in center of a box?
– Kiyoshi
Apr 27 '14 at 10:17
@Kiyoshi makebox centres by default, so the characters should be horizontally centred, and by adjusting the height and depth you use in the strut you can make the baseline be wherever you want or do you want an A to be lower than an a so they are individually centred rather than being on the same baseline?
– David Carlisle
Apr 27 '14 at 10:20
Exactly, I want a individually centred.
– Kiyoshi
Apr 27 '14 at 10:30
|
show 1 more comment
David your solution is a very good and simple solution, but I want a smaller height.
– Kiyoshi
Apr 27 '14 at 9:35
@Kiyoshi replacestrutbyrule[1pt]{0pt}{5pt}replacing 1 and 5 for whatever depth and height you want
– David Carlisle
Apr 27 '14 at 9:52
If possible to create acolorboxwith the same width and height for all character but the characters in center of a box?
– Kiyoshi
Apr 27 '14 at 10:17
@Kiyoshi makebox centres by default, so the characters should be horizontally centred, and by adjusting the height and depth you use in the strut you can make the baseline be wherever you want or do you want an A to be lower than an a so they are individually centred rather than being on the same baseline?
– David Carlisle
Apr 27 '14 at 10:20
Exactly, I want a individually centred.
– Kiyoshi
Apr 27 '14 at 10:30
David your solution is a very good and simple solution, but I want a smaller height.
– Kiyoshi
Apr 27 '14 at 9:35
David your solution is a very good and simple solution, but I want a smaller height.
– Kiyoshi
Apr 27 '14 at 9:35
@Kiyoshi replace
strut by rule[1pt]{0pt}{5pt} replacing 1 and 5 for whatever depth and height you want– David Carlisle
Apr 27 '14 at 9:52
@Kiyoshi replace
strut by rule[1pt]{0pt}{5pt} replacing 1 and 5 for whatever depth and height you want– David Carlisle
Apr 27 '14 at 9:52
If possible to create a
colorbox with the same width and height for all character but the characters in center of a box?– Kiyoshi
Apr 27 '14 at 10:17
If possible to create a
colorbox with the same width and height for all character but the characters in center of a box?– Kiyoshi
Apr 27 '14 at 10:17
@Kiyoshi makebox centres by default, so the characters should be horizontally centred, and by adjusting the height and depth you use in the strut you can make the baseline be wherever you want or do you want an A to be lower than an a so they are individually centred rather than being on the same baseline?
– David Carlisle
Apr 27 '14 at 10:20
@Kiyoshi makebox centres by default, so the characters should be horizontally centred, and by adjusting the height and depth you use in the strut you can make the baseline be wherever you want or do you want an A to be lower than an a so they are individually centred rather than being on the same baseline?
– David Carlisle
Apr 27 '14 at 10:20
Exactly, I want a individually centred.
– Kiyoshi
Apr 27 '14 at 10:30
Exactly, I want a individually centred.
– Kiyoshi
Apr 27 '14 at 10:30
|
show 1 more comment
With tikz:
documentclass{article}
usepackage{tikz}
newcommandcoloredtext[2]{tikz[baseline=(char.base)]node[minimum width=2em,text height=1.5ex, text depth=0.1ex,fill=black!85,text=white,#1](char){#2};}%
begin{document}
noindent
foreach x in {a,b,...,z}{%
coloredtext{x},
}
noindent
foreach x in {A,B,...,Z}{%
coloredtext[minimum width=2.55em]{x}
}%
end{document}

I can control perfectly the width and the height, if is possible to center the character in a box that would be amazing ;)
– Kiyoshi
Apr 27 '14 at 10:00
@Kiyoshi They are already centered horizontally by default.
– user11232
Apr 27 '14 at 12:53
add a comment |
With tikz:
documentclass{article}
usepackage{tikz}
newcommandcoloredtext[2]{tikz[baseline=(char.base)]node[minimum width=2em,text height=1.5ex, text depth=0.1ex,fill=black!85,text=white,#1](char){#2};}%
begin{document}
noindent
foreach x in {a,b,...,z}{%
coloredtext{x},
}
noindent
foreach x in {A,B,...,Z}{%
coloredtext[minimum width=2.55em]{x}
}%
end{document}

I can control perfectly the width and the height, if is possible to center the character in a box that would be amazing ;)
– Kiyoshi
Apr 27 '14 at 10:00
@Kiyoshi They are already centered horizontally by default.
– user11232
Apr 27 '14 at 12:53
add a comment |
With tikz:
documentclass{article}
usepackage{tikz}
newcommandcoloredtext[2]{tikz[baseline=(char.base)]node[minimum width=2em,text height=1.5ex, text depth=0.1ex,fill=black!85,text=white,#1](char){#2};}%
begin{document}
noindent
foreach x in {a,b,...,z}{%
coloredtext{x},
}
noindent
foreach x in {A,B,...,Z}{%
coloredtext[minimum width=2.55em]{x}
}%
end{document}

With tikz:
documentclass{article}
usepackage{tikz}
newcommandcoloredtext[2]{tikz[baseline=(char.base)]node[minimum width=2em,text height=1.5ex, text depth=0.1ex,fill=black!85,text=white,#1](char){#2};}%
begin{document}
noindent
foreach x in {a,b,...,z}{%
coloredtext{x},
}
noindent
foreach x in {A,B,...,Z}{%
coloredtext[minimum width=2.55em]{x}
}%
end{document}

answered Apr 27 '14 at 1:22
user11232
I can control perfectly the width and the height, if is possible to center the character in a box that would be amazing ;)
– Kiyoshi
Apr 27 '14 at 10:00
@Kiyoshi They are already centered horizontally by default.
– user11232
Apr 27 '14 at 12:53
add a comment |
I can control perfectly the width and the height, if is possible to center the character in a box that would be amazing ;)
– Kiyoshi
Apr 27 '14 at 10:00
@Kiyoshi They are already centered horizontally by default.
– user11232
Apr 27 '14 at 12:53
I can control perfectly the width and the height, if is possible to center the character in a box that would be amazing ;)
– Kiyoshi
Apr 27 '14 at 10:00
I can control perfectly the width and the height, if is possible to center the character in a box that would be amazing ;)
– Kiyoshi
Apr 27 '14 at 10:00
@Kiyoshi They are already centered horizontally by default.
– user11232
Apr 27 '14 at 12:53
@Kiyoshi They are already centered horizontally by default.
– user11232
Apr 27 '14 at 12:53
add a comment |
I would suggest using the eqparbox package, if you want to have equal and minimal widths of the boxes (two runs are required):
documentclass[11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{fourier}
usepackage{eqparbox}
usepackage[x11names]{xcolor}
begin{document}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}I}}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}W}}
end{document}

If you want the coloured boxes to have the same heights, while keeping the natural width of the widest, you can adjust the height in two ways:
- Either insert a
vphantom{highest entry}as an argument toeqmakebox. Of course, it's up to you to decide which will be the highest entry. One may turn it into an optional argument of a macro. - Or insert an invisible rule that lets you predefine the height of the box.
I give an example of both, the second solution with predefined height equal to 1 cm. This can make possible fancy effects.
documentclass[11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{fourier}
usepackage{eqparbox}
usepackage[x11names]{xcolor}
begin{document}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}I}}
enspace
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}W}}
enspace
colorbox{DeepPink4}{eqmakebox[L]{vphantom{Largebfseries W}footnotesizebfseriescolor{AntiqueWhite1}W}}
enspace\
colorbox{AntiqueWhite1}{eqmakebox[L]{rule{0pt}{dimexpr 1cm-2fboxseprelax}Largebfseriescolor{DeepPink4}W}}
enspace
colorbox{AntiqueWhite1}{eqmakebox[L]{rule{0pt}{dimexpr 1cm-2fboxseprelax}footnotesizebfseriescolor{DeepPink4}i}}
enspace\
colorbox{AntiqueWhite1}{eqmakebox[L]{rule[-0.4cm]{0pt}{dimexpr 1cm-2fboxseprelax}Largebfseriescolor{DeepPink4}W}}
enspace
colorbox{AntiqueWhite1}{eqmakebox[L]{rule[-0.4cm]{0pt}{dimexpr 1cm-2fboxseprelax}footnotesizebfseriescolor{DeepPink4}i}}
end{document}

The problem witheqparboxis when I adjust the box to a character normal size the height is not equal.
– Kiyoshi
Apr 27 '14 at 9:46
@ Kiyoshi: Do you mean that if your letters have different sizes, hence differnt heights, the height of the coloured boxes will be different, and you'd like it to be the same?
– Bernard
Apr 27 '14 at 10:55
@ Bernard: Same size and centred
– Kiyoshi
Apr 27 '14 at 10:58
@Kiyoshi: Updated my answer. I added two solutions to the height problem.
– Bernard
Apr 27 '14 at 12:14
add a comment |
I would suggest using the eqparbox package, if you want to have equal and minimal widths of the boxes (two runs are required):
documentclass[11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{fourier}
usepackage{eqparbox}
usepackage[x11names]{xcolor}
begin{document}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}I}}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}W}}
end{document}

If you want the coloured boxes to have the same heights, while keeping the natural width of the widest, you can adjust the height in two ways:
- Either insert a
vphantom{highest entry}as an argument toeqmakebox. Of course, it's up to you to decide which will be the highest entry. One may turn it into an optional argument of a macro. - Or insert an invisible rule that lets you predefine the height of the box.
I give an example of both, the second solution with predefined height equal to 1 cm. This can make possible fancy effects.
documentclass[11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{fourier}
usepackage{eqparbox}
usepackage[x11names]{xcolor}
begin{document}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}I}}
enspace
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}W}}
enspace
colorbox{DeepPink4}{eqmakebox[L]{vphantom{Largebfseries W}footnotesizebfseriescolor{AntiqueWhite1}W}}
enspace\
colorbox{AntiqueWhite1}{eqmakebox[L]{rule{0pt}{dimexpr 1cm-2fboxseprelax}Largebfseriescolor{DeepPink4}W}}
enspace
colorbox{AntiqueWhite1}{eqmakebox[L]{rule{0pt}{dimexpr 1cm-2fboxseprelax}footnotesizebfseriescolor{DeepPink4}i}}
enspace\
colorbox{AntiqueWhite1}{eqmakebox[L]{rule[-0.4cm]{0pt}{dimexpr 1cm-2fboxseprelax}Largebfseriescolor{DeepPink4}W}}
enspace
colorbox{AntiqueWhite1}{eqmakebox[L]{rule[-0.4cm]{0pt}{dimexpr 1cm-2fboxseprelax}footnotesizebfseriescolor{DeepPink4}i}}
end{document}

The problem witheqparboxis when I adjust the box to a character normal size the height is not equal.
– Kiyoshi
Apr 27 '14 at 9:46
@ Kiyoshi: Do you mean that if your letters have different sizes, hence differnt heights, the height of the coloured boxes will be different, and you'd like it to be the same?
– Bernard
Apr 27 '14 at 10:55
@ Bernard: Same size and centred
– Kiyoshi
Apr 27 '14 at 10:58
@Kiyoshi: Updated my answer. I added two solutions to the height problem.
– Bernard
Apr 27 '14 at 12:14
add a comment |
I would suggest using the eqparbox package, if you want to have equal and minimal widths of the boxes (two runs are required):
documentclass[11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{fourier}
usepackage{eqparbox}
usepackage[x11names]{xcolor}
begin{document}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}I}}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}W}}
end{document}

If you want the coloured boxes to have the same heights, while keeping the natural width of the widest, you can adjust the height in two ways:
- Either insert a
vphantom{highest entry}as an argument toeqmakebox. Of course, it's up to you to decide which will be the highest entry. One may turn it into an optional argument of a macro. - Or insert an invisible rule that lets you predefine the height of the box.
I give an example of both, the second solution with predefined height equal to 1 cm. This can make possible fancy effects.
documentclass[11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{fourier}
usepackage{eqparbox}
usepackage[x11names]{xcolor}
begin{document}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}I}}
enspace
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}W}}
enspace
colorbox{DeepPink4}{eqmakebox[L]{vphantom{Largebfseries W}footnotesizebfseriescolor{AntiqueWhite1}W}}
enspace\
colorbox{AntiqueWhite1}{eqmakebox[L]{rule{0pt}{dimexpr 1cm-2fboxseprelax}Largebfseriescolor{DeepPink4}W}}
enspace
colorbox{AntiqueWhite1}{eqmakebox[L]{rule{0pt}{dimexpr 1cm-2fboxseprelax}footnotesizebfseriescolor{DeepPink4}i}}
enspace\
colorbox{AntiqueWhite1}{eqmakebox[L]{rule[-0.4cm]{0pt}{dimexpr 1cm-2fboxseprelax}Largebfseriescolor{DeepPink4}W}}
enspace
colorbox{AntiqueWhite1}{eqmakebox[L]{rule[-0.4cm]{0pt}{dimexpr 1cm-2fboxseprelax}footnotesizebfseriescolor{DeepPink4}i}}
end{document}

I would suggest using the eqparbox package, if you want to have equal and minimal widths of the boxes (two runs are required):
documentclass[11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{fourier}
usepackage{eqparbox}
usepackage[x11names]{xcolor}
begin{document}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}I}}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}W}}
end{document}

If you want the coloured boxes to have the same heights, while keeping the natural width of the widest, you can adjust the height in two ways:
- Either insert a
vphantom{highest entry}as an argument toeqmakebox. Of course, it's up to you to decide which will be the highest entry. One may turn it into an optional argument of a macro. - Or insert an invisible rule that lets you predefine the height of the box.
I give an example of both, the second solution with predefined height equal to 1 cm. This can make possible fancy effects.
documentclass[11pt]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{fourier}
usepackage{eqparbox}
usepackage[x11names]{xcolor}
begin{document}
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}I}}
enspace
colorbox{DeepPink4}{eqmakebox[L]{Largebfseriescolor{AntiqueWhite1}W}}
enspace
colorbox{DeepPink4}{eqmakebox[L]{vphantom{Largebfseries W}footnotesizebfseriescolor{AntiqueWhite1}W}}
enspace\
colorbox{AntiqueWhite1}{eqmakebox[L]{rule{0pt}{dimexpr 1cm-2fboxseprelax}Largebfseriescolor{DeepPink4}W}}
enspace
colorbox{AntiqueWhite1}{eqmakebox[L]{rule{0pt}{dimexpr 1cm-2fboxseprelax}footnotesizebfseriescolor{DeepPink4}i}}
enspace\
colorbox{AntiqueWhite1}{eqmakebox[L]{rule[-0.4cm]{0pt}{dimexpr 1cm-2fboxseprelax}Largebfseriescolor{DeepPink4}W}}
enspace
colorbox{AntiqueWhite1}{eqmakebox[L]{rule[-0.4cm]{0pt}{dimexpr 1cm-2fboxseprelax}footnotesizebfseriescolor{DeepPink4}i}}
end{document}

edited Jun 21 '15 at 11:18
answered Apr 27 '14 at 1:40
Bernard
166k769194
166k769194
The problem witheqparboxis when I adjust the box to a character normal size the height is not equal.
– Kiyoshi
Apr 27 '14 at 9:46
@ Kiyoshi: Do you mean that if your letters have different sizes, hence differnt heights, the height of the coloured boxes will be different, and you'd like it to be the same?
– Bernard
Apr 27 '14 at 10:55
@ Bernard: Same size and centred
– Kiyoshi
Apr 27 '14 at 10:58
@Kiyoshi: Updated my answer. I added two solutions to the height problem.
– Bernard
Apr 27 '14 at 12:14
add a comment |
The problem witheqparboxis when I adjust the box to a character normal size the height is not equal.
– Kiyoshi
Apr 27 '14 at 9:46
@ Kiyoshi: Do you mean that if your letters have different sizes, hence differnt heights, the height of the coloured boxes will be different, and you'd like it to be the same?
– Bernard
Apr 27 '14 at 10:55
@ Bernard: Same size and centred
– Kiyoshi
Apr 27 '14 at 10:58
@Kiyoshi: Updated my answer. I added two solutions to the height problem.
– Bernard
Apr 27 '14 at 12:14
The problem with
eqparbox is when I adjust the box to a character normal size the height is not equal.– Kiyoshi
Apr 27 '14 at 9:46
The problem with
eqparbox is when I adjust the box to a character normal size the height is not equal.– Kiyoshi
Apr 27 '14 at 9:46
@ Kiyoshi: Do you mean that if your letters have different sizes, hence differnt heights, the height of the coloured boxes will be different, and you'd like it to be the same?
– Bernard
Apr 27 '14 at 10:55
@ Kiyoshi: Do you mean that if your letters have different sizes, hence differnt heights, the height of the coloured boxes will be different, and you'd like it to be the same?
– Bernard
Apr 27 '14 at 10:55
@ Bernard: Same size and centred
– Kiyoshi
Apr 27 '14 at 10:58
@ Bernard: Same size and centred
– Kiyoshi
Apr 27 '14 at 10:58
@Kiyoshi: Updated my answer. I added two solutions to the height problem.
– Bernard
Apr 27 '14 at 12:14
@Kiyoshi: Updated my answer. I added two solutions to the height problem.
– Bernard
Apr 27 '14 at 12:14
add a comment |
The first optional argument is the textcolor and the second is the background color.
documentclass{article}
usepackage[x11names]{xcolor}
makeatletter
defCbox{@ifnextchar[Cbox@i{Cbox@i[white]}}
defCbox@i[#1]{@ifnextchar[{Cbox@ii[#1]}{Cbox@ii[#1][black]}}
defCbox@ii[#1][#2]#3{colorbox{#2}{makebox[1em]{struttextcolor{#1}{#3}}}}
makeatother
begin{document}
Cbox{I} Cbox[yellow]{g} Cbox[AntiqueWhite1][DeepPink4]{W}
end{document}

Nice solution, but I want a smaller height box.
– Kiyoshi
Apr 27 '14 at 9:52
add a comment |
The first optional argument is the textcolor and the second is the background color.
documentclass{article}
usepackage[x11names]{xcolor}
makeatletter
defCbox{@ifnextchar[Cbox@i{Cbox@i[white]}}
defCbox@i[#1]{@ifnextchar[{Cbox@ii[#1]}{Cbox@ii[#1][black]}}
defCbox@ii[#1][#2]#3{colorbox{#2}{makebox[1em]{struttextcolor{#1}{#3}}}}
makeatother
begin{document}
Cbox{I} Cbox[yellow]{g} Cbox[AntiqueWhite1][DeepPink4]{W}
end{document}

Nice solution, but I want a smaller height box.
– Kiyoshi
Apr 27 '14 at 9:52
add a comment |
The first optional argument is the textcolor and the second is the background color.
documentclass{article}
usepackage[x11names]{xcolor}
makeatletter
defCbox{@ifnextchar[Cbox@i{Cbox@i[white]}}
defCbox@i[#1]{@ifnextchar[{Cbox@ii[#1]}{Cbox@ii[#1][black]}}
defCbox@ii[#1][#2]#3{colorbox{#2}{makebox[1em]{struttextcolor{#1}{#3}}}}
makeatother
begin{document}
Cbox{I} Cbox[yellow]{g} Cbox[AntiqueWhite1][DeepPink4]{W}
end{document}

The first optional argument is the textcolor and the second is the background color.
documentclass{article}
usepackage[x11names]{xcolor}
makeatletter
defCbox{@ifnextchar[Cbox@i{Cbox@i[white]}}
defCbox@i[#1]{@ifnextchar[{Cbox@ii[#1]}{Cbox@ii[#1][black]}}
defCbox@ii[#1][#2]#3{colorbox{#2}{makebox[1em]{struttextcolor{#1}{#3}}}}
makeatother
begin{document}
Cbox{I} Cbox[yellow]{g} Cbox[AntiqueWhite1][DeepPink4]{W}
end{document}

answered Apr 27 '14 at 7:09
Herbert
270k24408717
270k24408717
Nice solution, but I want a smaller height box.
– Kiyoshi
Apr 27 '14 at 9:52
add a comment |
Nice solution, but I want a smaller height box.
– Kiyoshi
Apr 27 '14 at 9:52
Nice solution, but I want a smaller height box.
– Kiyoshi
Apr 27 '14 at 9:52
Nice solution, but I want a smaller height box.
– Kiyoshi
Apr 27 '14 at 9:52
add a comment |
Here a solution with the adjustbox package. You can create the centered box using the center=<width> key. Adding strut gives you the same height and depths independent of the character size. If you use htstrutbox+dpstrutbox as the width you will get a nice square.
documentclass{article}
usepackage{xcolor}
usepackage{adjustbox}
newcommandblackboxchar[1]{noindent
adjustbox{center=htstrutbox+dpstrutbox,frame,bgcolor=black!85}{color{white}strut #1}}
begin{document}
begin{itemize}
item[blackboxchar{i}] text text text text
item[blackboxchar{a}] text text text text
item[blackboxchar{m}] text text text text
end{itemize}
end{document}

add a comment |
Here a solution with the adjustbox package. You can create the centered box using the center=<width> key. Adding strut gives you the same height and depths independent of the character size. If you use htstrutbox+dpstrutbox as the width you will get a nice square.
documentclass{article}
usepackage{xcolor}
usepackage{adjustbox}
newcommandblackboxchar[1]{noindent
adjustbox{center=htstrutbox+dpstrutbox,frame,bgcolor=black!85}{color{white}strut #1}}
begin{document}
begin{itemize}
item[blackboxchar{i}] text text text text
item[blackboxchar{a}] text text text text
item[blackboxchar{m}] text text text text
end{itemize}
end{document}

add a comment |
Here a solution with the adjustbox package. You can create the centered box using the center=<width> key. Adding strut gives you the same height and depths independent of the character size. If you use htstrutbox+dpstrutbox as the width you will get a nice square.
documentclass{article}
usepackage{xcolor}
usepackage{adjustbox}
newcommandblackboxchar[1]{noindent
adjustbox{center=htstrutbox+dpstrutbox,frame,bgcolor=black!85}{color{white}strut #1}}
begin{document}
begin{itemize}
item[blackboxchar{i}] text text text text
item[blackboxchar{a}] text text text text
item[blackboxchar{m}] text text text text
end{itemize}
end{document}

Here a solution with the adjustbox package. You can create the centered box using the center=<width> key. Adding strut gives you the same height and depths independent of the character size. If you use htstrutbox+dpstrutbox as the width you will get a nice square.
documentclass{article}
usepackage{xcolor}
usepackage{adjustbox}
newcommandblackboxchar[1]{noindent
adjustbox{center=htstrutbox+dpstrutbox,frame,bgcolor=black!85}{color{white}strut #1}}
begin{document}
begin{itemize}
item[blackboxchar{i}] text text text text
item[blackboxchar{a}] text text text text
item[blackboxchar{m}] text text text text
end{itemize}
end{document}

answered Dec 27 '18 at 15:13
Martin Scharrer♦
199k45632815
199k45632815
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f173695%2fset-size-of-colorbox-for-a-single-character%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown