How to put “+” and “x” after hline in tabular, and reducing space?
I want to write "+" and "x" after hline, and I want reducing the space between number and number.
From this
become
This is my code
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
begin{document}
begin{center}
begin{tabular}{cccccccc}
&&&&6&0&0&1\
&&&&&2&7&2\
hline$times$
&&&1&4&0&0&2\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$cdot$\
hline$+$
&2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
tables spacing
add a comment |
I want to write "+" and "x" after hline, and I want reducing the space between number and number.
From this
become
This is my code
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
begin{document}
begin{center}
begin{tabular}{cccccccc}
&&&&6&0&0&1\
&&&&&2&7&2\
hline$times$
&&&1&4&0&0&2\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$cdot$\
hline$+$
&2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
tables spacing
add a comment |
I want to write "+" and "x" after hline, and I want reducing the space between number and number.
From this
become
This is my code
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
begin{document}
begin{center}
begin{tabular}{cccccccc}
&&&&6&0&0&1\
&&&&&2&7&2\
hline$times$
&&&1&4&0&0&2\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$cdot$\
hline$+$
&2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
tables spacing
I want to write "+" and "x" after hline, and I want reducing the space between number and number.
From this
become
This is my code
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
begin{document}
begin{center}
begin{tabular}{cccccccc}
&&&&6&0&0&1\
&&&&&2&7&2\
hline$times$
&&&1&4&0&0&2\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$cdot$\
hline$+$
&2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
tables spacing
tables spacing
edited Dec 23 '18 at 7:18
CarLaTeX
29.9k447127
29.9k447127
asked Dec 23 '18 at 1:52
Ongky Denny Wijaya
1237
1237
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
Not that I like this from a mathematical point of view, but…
documentclass{article}
usepackage{array}
newenvironment{multiplication}[1]
{% #1 = number of digits in the result
setlength{arraycolsep}{1pt}%
renewcommand{arraystretch}{0}%
newcommand{size}{#1}%
mathcode`*=cdot
begin{array}{*{#1}{>{strut}c} c}
}
{end{array}}
newcommand{dividerline}[1]{% #1 = symbol
multicolumn{size}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
begin{document}
[
begin{multiplication}{7}
& & & 6 & 0 & 0 & 1 \
& & & & 2 & 7 & 2 \ dividerline{times}
& & 1 & 4 & 0 & 0 & 2 \
& 5 & 2 & 0 & 0 & 7 & * \
1 & 4 & 0 & 0 & 2 & * & * \ dividerline{+}
2 & 1 & 3 & 4 & 2 & 7 & 2
end{multiplication}
]
end{document}
A “slightly” more complicated version that allows you not to do calculations error like in the above scheme. ;-)
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mm}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% the main command
ensuremath { ongky_multiply:nnn { #1 } { #2 } { #3 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new_protected:Nn ongky_multiply:nnn
{
tl_set:Nx l__ongky_multiply_first_tl { int_eval:n { #2 } }
tl_set:Nx l__ongky_multiply_second_tl { int_eval:n { #3 } }
tl_set:Nx l__ongky_multiply_result_tl { int_eval:n { (#2)*(#3) } }
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
int_eval:n
{
l__ongky_multiply_first_tl *
tl_item:Nn l__ongky_multiply_second_tl { -##1 }
}
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}
end{document}
A more efficient code using tl_build
experimental features:
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mm}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% the main command
ensuremath { ongky_multiply:nnn { #1 } { #2 } { #3 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new_protected:Nn ongky_multiply:nnn
{
tl_set:Nx l__ongky_multiply_first_tl { int_eval:n { #2 } }
tl_set:Nx l__ongky_multiply_second_tl { int_eval:n { #3 } }
tl_set:Nx l__ongky_multiply_result_tl { int_eval:n { (#2)*(#3) } }
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
int_eval:n
{
l__ongky_multiply_first_tl *
tl_item:Nn l__ongky_multiply_second_tl { -##1 }
}
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
tl_build_begin:N l__ongky_multiply_output_tl
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
tl_build_end:N l__ongky_multiply_output_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_build_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_build_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}
end{document}
Season’s gift: a version that allows any base from 2 to 36
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mmO{10}}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% dirty trick for letters
sbox0{$mathtt{int_gset:Nn g_tmpa_int {mathgroup}}$}
int_step_inline:nnn { `A } { `Z }
{
mathcode ##1=int_eval:n { g_tmpa_int * 16 * 16 + ##1 }
}
% the main command
ensuremath { ongky_multiply:nnnn { #1 } { #2 } { #3 } { #4 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new:Nn __ongky_multiply_base:nnn
{
int_to_Base:nn { int_from_base:nn { #1 } { #3 } * int_from_base:nn { #2 } { #3 } } { #3 }
}
cs_generate_variant:Nn __ongky_multiply_base:nnn { ff }
cs_new_protected:Nn ongky_multiply:nnnn
{
tl_set:Nx l__ongky_multiply_first_tl { #2 }
tl_set:Nx l__ongky_multiply_second_tl { #3 }
tl_set:Nx l__ongky_multiply_result_tl
{
__ongky_multiply_base:nnn { #2 } { #3 } { #4 }
}
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
__ongky_multiply_base:ffn
{ l__ongky_multiply_first_tl }
{ tl_item:Nn l__ongky_multiply_second_tl { -##1 } }
{ #4 }
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
tl_build_begin:N l__ongky_multiply_output_tl
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
tl_build_end:N l__ongky_multiply_output_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_build_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_build_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}qquad
multiplication{6001}{272}[8]qquad
multiplication{6001}{272}[16]qquad
multiplication{6001}{272}[36]
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}qquad
multiplication[t]{32}{444}[5]qquad
multiplication[t]{444}{32}[5]qquad
end{document}
In the first row the multiplications are in base 10, 8, 16 and 36 respectively.
In the second row the first two are in base 10, the last two in base 5.
By the way, that is multiplication between two octal numbers, not decimal numbers. But, thanks for your help.
– Ongky Denny Wijaya
Dec 24 '18 at 3:36
1
@OngkyDennyWijaya I put online a new version you may enjoy!
– egreg
Dec 24 '18 at 11:30
Best answer! Thanks for helping me!
– Ongky Denny Wijaya
Dec 26 '18 at 11:34
add a comment |
TikZ is overkilling here, just simply use multirow
s and cline
s.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
usepackage{multirow}
begin{document}
begin{center}
setlengthtabcolsep{1pt}
begin{tabular}{*{8}{c}}
&&&6&0&0&1\
&&&&2&7&2&multirow{2}{*}[-.2pt]{$times$}\
cline{1-7}
&&1&4&0&0&2\
&5&2&0&0&7&$cdot$\
1&4&0&0&2&$cdot$&$cdot$&multirow{2}{*}[-.2pt]{$+$}\
cline{1-7}
2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
Thanks, for your help
– Ongky Denny Wijaya
Dec 24 '18 at 3:43
@OngkyDennyWijaya You're welcome!
– CarLaTeX
Dec 24 '18 at 4:24
add a comment |
Here is a proposal. Decreasing the distance is standard. In order to place the symbols, I am loading TikZ. Loading TikZ for only this may be overkill.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
usepackage{tikz}
usetikzlibrary{tikzmark,calc}
begin{document}
begin{center}
begin{tabular}{*{8}{@{,}c}}
&&&&6&0&0&1\
&&&&&2&7&tikzmarknode{2a}{2}\
hline %$times$
&&&1&4&0&0&tikzmarknode{2b}{2}\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$tikzmarknode{dot}{cdot}$\
hline%$+$
&2&1&3&4&2&7&tikzmarknode{2c}{2}
end{tabular}
begin{tikzpicture}[overlay,remember picture]
node at ([xshift=5mm]$(2a.south)!0.6!(2b.north)$) {$times$};
node at ([xshift=5mm]$(dot.south)!0.6!(2c.north)$) {$+$};
end{tikzpicture}
end{center}
end{document}
2
+1. As a "good housekeeping" measure, maybe also replaceleft=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm
withmargin=2cm
?
– Mico
Dec 23 '18 at 5:46
add a comment |
To snug up the numerals, all you need to do is add the instruction setlengthtabcolsep{0pt}
. If the result looks too tight, maybe try setlengthtabcolsep{0.25pt}
.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[margin=2cm]{geometry}
begin{document}
begin{center}
setlengthtabcolsep{0pt} % <-- new
begin{tabular}{cccccccc}
&&&&6&0&0&1\
&&&&&2&7&2\
hline$times$
&&&1&4&0&0&2\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$cdot$\
hline$+$
&2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
for this code, plus and times sign are not in the right of line, but thanks for your answer.
– Ongky Denny Wijaya
Dec 24 '18 at 3:40
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%2f467054%2fhow-to-put-and-x-after-hline-in-tabular-and-reducing-space%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Not that I like this from a mathematical point of view, but…
documentclass{article}
usepackage{array}
newenvironment{multiplication}[1]
{% #1 = number of digits in the result
setlength{arraycolsep}{1pt}%
renewcommand{arraystretch}{0}%
newcommand{size}{#1}%
mathcode`*=cdot
begin{array}{*{#1}{>{strut}c} c}
}
{end{array}}
newcommand{dividerline}[1]{% #1 = symbol
multicolumn{size}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
begin{document}
[
begin{multiplication}{7}
& & & 6 & 0 & 0 & 1 \
& & & & 2 & 7 & 2 \ dividerline{times}
& & 1 & 4 & 0 & 0 & 2 \
& 5 & 2 & 0 & 0 & 7 & * \
1 & 4 & 0 & 0 & 2 & * & * \ dividerline{+}
2 & 1 & 3 & 4 & 2 & 7 & 2
end{multiplication}
]
end{document}
A “slightly” more complicated version that allows you not to do calculations error like in the above scheme. ;-)
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mm}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% the main command
ensuremath { ongky_multiply:nnn { #1 } { #2 } { #3 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new_protected:Nn ongky_multiply:nnn
{
tl_set:Nx l__ongky_multiply_first_tl { int_eval:n { #2 } }
tl_set:Nx l__ongky_multiply_second_tl { int_eval:n { #3 } }
tl_set:Nx l__ongky_multiply_result_tl { int_eval:n { (#2)*(#3) } }
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
int_eval:n
{
l__ongky_multiply_first_tl *
tl_item:Nn l__ongky_multiply_second_tl { -##1 }
}
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}
end{document}
A more efficient code using tl_build
experimental features:
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mm}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% the main command
ensuremath { ongky_multiply:nnn { #1 } { #2 } { #3 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new_protected:Nn ongky_multiply:nnn
{
tl_set:Nx l__ongky_multiply_first_tl { int_eval:n { #2 } }
tl_set:Nx l__ongky_multiply_second_tl { int_eval:n { #3 } }
tl_set:Nx l__ongky_multiply_result_tl { int_eval:n { (#2)*(#3) } }
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
int_eval:n
{
l__ongky_multiply_first_tl *
tl_item:Nn l__ongky_multiply_second_tl { -##1 }
}
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
tl_build_begin:N l__ongky_multiply_output_tl
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
tl_build_end:N l__ongky_multiply_output_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_build_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_build_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}
end{document}
Season’s gift: a version that allows any base from 2 to 36
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mmO{10}}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% dirty trick for letters
sbox0{$mathtt{int_gset:Nn g_tmpa_int {mathgroup}}$}
int_step_inline:nnn { `A } { `Z }
{
mathcode ##1=int_eval:n { g_tmpa_int * 16 * 16 + ##1 }
}
% the main command
ensuremath { ongky_multiply:nnnn { #1 } { #2 } { #3 } { #4 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new:Nn __ongky_multiply_base:nnn
{
int_to_Base:nn { int_from_base:nn { #1 } { #3 } * int_from_base:nn { #2 } { #3 } } { #3 }
}
cs_generate_variant:Nn __ongky_multiply_base:nnn { ff }
cs_new_protected:Nn ongky_multiply:nnnn
{
tl_set:Nx l__ongky_multiply_first_tl { #2 }
tl_set:Nx l__ongky_multiply_second_tl { #3 }
tl_set:Nx l__ongky_multiply_result_tl
{
__ongky_multiply_base:nnn { #2 } { #3 } { #4 }
}
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
__ongky_multiply_base:ffn
{ l__ongky_multiply_first_tl }
{ tl_item:Nn l__ongky_multiply_second_tl { -##1 } }
{ #4 }
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
tl_build_begin:N l__ongky_multiply_output_tl
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
tl_build_end:N l__ongky_multiply_output_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_build_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_build_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}qquad
multiplication{6001}{272}[8]qquad
multiplication{6001}{272}[16]qquad
multiplication{6001}{272}[36]
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}qquad
multiplication[t]{32}{444}[5]qquad
multiplication[t]{444}{32}[5]qquad
end{document}
In the first row the multiplications are in base 10, 8, 16 and 36 respectively.
In the second row the first two are in base 10, the last two in base 5.
By the way, that is multiplication between two octal numbers, not decimal numbers. But, thanks for your help.
– Ongky Denny Wijaya
Dec 24 '18 at 3:36
1
@OngkyDennyWijaya I put online a new version you may enjoy!
– egreg
Dec 24 '18 at 11:30
Best answer! Thanks for helping me!
– Ongky Denny Wijaya
Dec 26 '18 at 11:34
add a comment |
Not that I like this from a mathematical point of view, but…
documentclass{article}
usepackage{array}
newenvironment{multiplication}[1]
{% #1 = number of digits in the result
setlength{arraycolsep}{1pt}%
renewcommand{arraystretch}{0}%
newcommand{size}{#1}%
mathcode`*=cdot
begin{array}{*{#1}{>{strut}c} c}
}
{end{array}}
newcommand{dividerline}[1]{% #1 = symbol
multicolumn{size}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
begin{document}
[
begin{multiplication}{7}
& & & 6 & 0 & 0 & 1 \
& & & & 2 & 7 & 2 \ dividerline{times}
& & 1 & 4 & 0 & 0 & 2 \
& 5 & 2 & 0 & 0 & 7 & * \
1 & 4 & 0 & 0 & 2 & * & * \ dividerline{+}
2 & 1 & 3 & 4 & 2 & 7 & 2
end{multiplication}
]
end{document}
A “slightly” more complicated version that allows you not to do calculations error like in the above scheme. ;-)
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mm}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% the main command
ensuremath { ongky_multiply:nnn { #1 } { #2 } { #3 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new_protected:Nn ongky_multiply:nnn
{
tl_set:Nx l__ongky_multiply_first_tl { int_eval:n { #2 } }
tl_set:Nx l__ongky_multiply_second_tl { int_eval:n { #3 } }
tl_set:Nx l__ongky_multiply_result_tl { int_eval:n { (#2)*(#3) } }
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
int_eval:n
{
l__ongky_multiply_first_tl *
tl_item:Nn l__ongky_multiply_second_tl { -##1 }
}
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}
end{document}
A more efficient code using tl_build
experimental features:
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mm}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% the main command
ensuremath { ongky_multiply:nnn { #1 } { #2 } { #3 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new_protected:Nn ongky_multiply:nnn
{
tl_set:Nx l__ongky_multiply_first_tl { int_eval:n { #2 } }
tl_set:Nx l__ongky_multiply_second_tl { int_eval:n { #3 } }
tl_set:Nx l__ongky_multiply_result_tl { int_eval:n { (#2)*(#3) } }
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
int_eval:n
{
l__ongky_multiply_first_tl *
tl_item:Nn l__ongky_multiply_second_tl { -##1 }
}
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
tl_build_begin:N l__ongky_multiply_output_tl
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
tl_build_end:N l__ongky_multiply_output_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_build_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_build_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}
end{document}
Season’s gift: a version that allows any base from 2 to 36
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mmO{10}}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% dirty trick for letters
sbox0{$mathtt{int_gset:Nn g_tmpa_int {mathgroup}}$}
int_step_inline:nnn { `A } { `Z }
{
mathcode ##1=int_eval:n { g_tmpa_int * 16 * 16 + ##1 }
}
% the main command
ensuremath { ongky_multiply:nnnn { #1 } { #2 } { #3 } { #4 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new:Nn __ongky_multiply_base:nnn
{
int_to_Base:nn { int_from_base:nn { #1 } { #3 } * int_from_base:nn { #2 } { #3 } } { #3 }
}
cs_generate_variant:Nn __ongky_multiply_base:nnn { ff }
cs_new_protected:Nn ongky_multiply:nnnn
{
tl_set:Nx l__ongky_multiply_first_tl { #2 }
tl_set:Nx l__ongky_multiply_second_tl { #3 }
tl_set:Nx l__ongky_multiply_result_tl
{
__ongky_multiply_base:nnn { #2 } { #3 } { #4 }
}
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
__ongky_multiply_base:ffn
{ l__ongky_multiply_first_tl }
{ tl_item:Nn l__ongky_multiply_second_tl { -##1 } }
{ #4 }
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
tl_build_begin:N l__ongky_multiply_output_tl
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
tl_build_end:N l__ongky_multiply_output_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_build_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_build_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}qquad
multiplication{6001}{272}[8]qquad
multiplication{6001}{272}[16]qquad
multiplication{6001}{272}[36]
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}qquad
multiplication[t]{32}{444}[5]qquad
multiplication[t]{444}{32}[5]qquad
end{document}
In the first row the multiplications are in base 10, 8, 16 and 36 respectively.
In the second row the first two are in base 10, the last two in base 5.
By the way, that is multiplication between two octal numbers, not decimal numbers. But, thanks for your help.
– Ongky Denny Wijaya
Dec 24 '18 at 3:36
1
@OngkyDennyWijaya I put online a new version you may enjoy!
– egreg
Dec 24 '18 at 11:30
Best answer! Thanks for helping me!
– Ongky Denny Wijaya
Dec 26 '18 at 11:34
add a comment |
Not that I like this from a mathematical point of view, but…
documentclass{article}
usepackage{array}
newenvironment{multiplication}[1]
{% #1 = number of digits in the result
setlength{arraycolsep}{1pt}%
renewcommand{arraystretch}{0}%
newcommand{size}{#1}%
mathcode`*=cdot
begin{array}{*{#1}{>{strut}c} c}
}
{end{array}}
newcommand{dividerline}[1]{% #1 = symbol
multicolumn{size}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
begin{document}
[
begin{multiplication}{7}
& & & 6 & 0 & 0 & 1 \
& & & & 2 & 7 & 2 \ dividerline{times}
& & 1 & 4 & 0 & 0 & 2 \
& 5 & 2 & 0 & 0 & 7 & * \
1 & 4 & 0 & 0 & 2 & * & * \ dividerline{+}
2 & 1 & 3 & 4 & 2 & 7 & 2
end{multiplication}
]
end{document}
A “slightly” more complicated version that allows you not to do calculations error like in the above scheme. ;-)
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mm}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% the main command
ensuremath { ongky_multiply:nnn { #1 } { #2 } { #3 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new_protected:Nn ongky_multiply:nnn
{
tl_set:Nx l__ongky_multiply_first_tl { int_eval:n { #2 } }
tl_set:Nx l__ongky_multiply_second_tl { int_eval:n { #3 } }
tl_set:Nx l__ongky_multiply_result_tl { int_eval:n { (#2)*(#3) } }
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
int_eval:n
{
l__ongky_multiply_first_tl *
tl_item:Nn l__ongky_multiply_second_tl { -##1 }
}
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}
end{document}
A more efficient code using tl_build
experimental features:
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mm}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% the main command
ensuremath { ongky_multiply:nnn { #1 } { #2 } { #3 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new_protected:Nn ongky_multiply:nnn
{
tl_set:Nx l__ongky_multiply_first_tl { int_eval:n { #2 } }
tl_set:Nx l__ongky_multiply_second_tl { int_eval:n { #3 } }
tl_set:Nx l__ongky_multiply_result_tl { int_eval:n { (#2)*(#3) } }
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
int_eval:n
{
l__ongky_multiply_first_tl *
tl_item:Nn l__ongky_multiply_second_tl { -##1 }
}
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
tl_build_begin:N l__ongky_multiply_output_tl
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
tl_build_end:N l__ongky_multiply_output_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_build_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_build_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}
end{document}
Season’s gift: a version that allows any base from 2 to 36
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mmO{10}}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% dirty trick for letters
sbox0{$mathtt{int_gset:Nn g_tmpa_int {mathgroup}}$}
int_step_inline:nnn { `A } { `Z }
{
mathcode ##1=int_eval:n { g_tmpa_int * 16 * 16 + ##1 }
}
% the main command
ensuremath { ongky_multiply:nnnn { #1 } { #2 } { #3 } { #4 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new:Nn __ongky_multiply_base:nnn
{
int_to_Base:nn { int_from_base:nn { #1 } { #3 } * int_from_base:nn { #2 } { #3 } } { #3 }
}
cs_generate_variant:Nn __ongky_multiply_base:nnn { ff }
cs_new_protected:Nn ongky_multiply:nnnn
{
tl_set:Nx l__ongky_multiply_first_tl { #2 }
tl_set:Nx l__ongky_multiply_second_tl { #3 }
tl_set:Nx l__ongky_multiply_result_tl
{
__ongky_multiply_base:nnn { #2 } { #3 } { #4 }
}
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
__ongky_multiply_base:ffn
{ l__ongky_multiply_first_tl }
{ tl_item:Nn l__ongky_multiply_second_tl { -##1 } }
{ #4 }
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
tl_build_begin:N l__ongky_multiply_output_tl
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
tl_build_end:N l__ongky_multiply_output_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_build_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_build_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}qquad
multiplication{6001}{272}[8]qquad
multiplication{6001}{272}[16]qquad
multiplication{6001}{272}[36]
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}qquad
multiplication[t]{32}{444}[5]qquad
multiplication[t]{444}{32}[5]qquad
end{document}
In the first row the multiplications are in base 10, 8, 16 and 36 respectively.
In the second row the first two are in base 10, the last two in base 5.
Not that I like this from a mathematical point of view, but…
documentclass{article}
usepackage{array}
newenvironment{multiplication}[1]
{% #1 = number of digits in the result
setlength{arraycolsep}{1pt}%
renewcommand{arraystretch}{0}%
newcommand{size}{#1}%
mathcode`*=cdot
begin{array}{*{#1}{>{strut}c} c}
}
{end{array}}
newcommand{dividerline}[1]{% #1 = symbol
multicolumn{size}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
begin{document}
[
begin{multiplication}{7}
& & & 6 & 0 & 0 & 1 \
& & & & 2 & 7 & 2 \ dividerline{times}
& & 1 & 4 & 0 & 0 & 2 \
& 5 & 2 & 0 & 0 & 7 & * \
1 & 4 & 0 & 0 & 2 & * & * \ dividerline{+}
2 & 1 & 3 & 4 & 2 & 7 & 2
end{multiplication}
]
end{document}
A “slightly” more complicated version that allows you not to do calculations error like in the above scheme. ;-)
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mm}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% the main command
ensuremath { ongky_multiply:nnn { #1 } { #2 } { #3 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new_protected:Nn ongky_multiply:nnn
{
tl_set:Nx l__ongky_multiply_first_tl { int_eval:n { #2 } }
tl_set:Nx l__ongky_multiply_second_tl { int_eval:n { #3 } }
tl_set:Nx l__ongky_multiply_result_tl { int_eval:n { (#2)*(#3) } }
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
int_eval:n
{
l__ongky_multiply_first_tl *
tl_item:Nn l__ongky_multiply_second_tl { -##1 }
}
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}
end{document}
A more efficient code using tl_build
experimental features:
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mm}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% the main command
ensuremath { ongky_multiply:nnn { #1 } { #2 } { #3 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new_protected:Nn ongky_multiply:nnn
{
tl_set:Nx l__ongky_multiply_first_tl { int_eval:n { #2 } }
tl_set:Nx l__ongky_multiply_second_tl { int_eval:n { #3 } }
tl_set:Nx l__ongky_multiply_result_tl { int_eval:n { (#2)*(#3) } }
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
int_eval:n
{
l__ongky_multiply_first_tl *
tl_item:Nn l__ongky_multiply_second_tl { -##1 }
}
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
tl_build_begin:N l__ongky_multiply_output_tl
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
tl_build_end:N l__ongky_multiply_output_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_build_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_build_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}
end{document}
Season’s gift: a version that allows any base from 2 to 36
documentclass{article}
usepackage{array,xparse}
ExplSyntaxOn
NewDocumentCommand{multiplication}{O{c}mmO{10}}
{
group_begin:
% some initializations
setlength{arraycolsep}{1pt}
renewcommand{arraystretch}{0}
mathcode`*=cdot
% dirty trick for letters
sbox0{$mathtt{int_gset:Nn g_tmpa_int {mathgroup}}$}
int_step_inline:nnn { `A } { `Z }
{
mathcode ##1=int_eval:n { g_tmpa_int * 16 * 16 + ##1 }
}
% the main command
ensuremath { ongky_multiply:nnnn { #1 } { #2 } { #3 } { #4 } }
% end the group
group_end:
}
tl_new:N l__ongky_multiply_first_tl
tl_new:N l__ongky_multiply_second_tl
tl_new:N l__ongky_multiply_result_tl
tl_new:N l__ongky_multiply_output_tl
seq_new:N l__ongky_multiply_summands_seq
int_new:N l__ongky_multiply_size_int
cs_new:Nn __ongky_multiply_base:nnn
{
int_to_Base:nn { int_from_base:nn { #1 } { #3 } * int_from_base:nn { #2 } { #3 } } { #3 }
}
cs_generate_variant:Nn __ongky_multiply_base:nnn { ff }
cs_new_protected:Nn ongky_multiply:nnnn
{
tl_set:Nx l__ongky_multiply_first_tl { #2 }
tl_set:Nx l__ongky_multiply_second_tl { #3 }
tl_set:Nx l__ongky_multiply_result_tl
{
__ongky_multiply_base:nnn { #2 } { #3 } { #4 }
}
int_set:Nn l__ongky_multiply_size_int { tl_count:N l__ongky_multiply_result_tl }
% create the numbers to sum up (padding with * on the right)
int_step_inline:nn { tl_count:N l__ongky_multiply_second_tl }
{
seq_put_right:Nx l__ongky_multiply_summands_seq
{
__ongky_multiply_base:ffn
{ l__ongky_multiply_first_tl }
{ tl_item:Nn l__ongky_multiply_second_tl { -##1 } }
{ #4 }
prg_replicate:nn { ##1 - 1 } { * }
}
}
% start building the body of the array
tl_build_begin:N l__ongky_multiply_output_tl
__ongky_multiply_put:V l__ongky_multiply_first_tl
__ongky_multiply_put:V l__ongky_multiply_second_tl
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { times } }
seq_map_inline:Nn l__ongky_multiply_summands_seq
{
__ongky_multiply_put:n { ##1 }
}
tl_build_put_right:Nn l__ongky_multiply_output_tl { __ongky_divider:n { + } }
__ongky_multiply_put:V l__ongky_multiply_result_tl
tl_build_end:N l__ongky_multiply_output_tl
% print the array
begin{array}[#1]{ *{l__ongky_multiply_size_int}{>{strut}c} c }
l__ongky_multiply_output_tl
end{array}
}
cs_new_protected:Nn __ongky_multiply_put:n
{
tl_set:Nx l__ongky_multiply_temp_tl
{
prg_replicate:nn { l__ongky_multiply_size_int - tl_count:n { #1 } } { {} }
#1
}
tl_map_function:NN l__ongky_multiply_temp_tl __ongky_multiply_put_item:n
tl_build_put_right:Nn l__ongky_multiply_output_tl { \ }
}
cs_generate_variant:Nn __ongky_multiply_put:n { V }
cs_new_protected:Nn __ongky_multiply_put_item:n
{
tl_build_put_right:Nn l__ongky_multiply_output_tl { #1 & }
}
cs_new:Nn __ongky_divider:n
{
multicolumn{l__ongky_multiply_size_int}{c}{%
leadershrule height dimexprfontdimen22textfont2+0.2ptrelax
depth -dimexprfontdimen22textfont2-0.2ptrelax
hfillkern0pt
}%
& smash{#1} \
}
ExplSyntaxOff
begin{document}
multiplication{6001}{272}qquad
multiplication{6001}{272}[8]qquad
multiplication{6001}{272}[16]qquad
multiplication{6001}{272}[36]
bigskip
multiplication[t]{32}{444}qquad
multiplication[t]{444}{32}qquad
multiplication[t]{32}{444}[5]qquad
multiplication[t]{444}{32}[5]qquad
end{document}
In the first row the multiplications are in base 10, 8, 16 and 36 respectively.
In the second row the first two are in base 10, the last two in base 5.
edited Dec 24 '18 at 11:29
answered Dec 23 '18 at 10:32
egreg
710k8618853168
710k8618853168
By the way, that is multiplication between two octal numbers, not decimal numbers. But, thanks for your help.
– Ongky Denny Wijaya
Dec 24 '18 at 3:36
1
@OngkyDennyWijaya I put online a new version you may enjoy!
– egreg
Dec 24 '18 at 11:30
Best answer! Thanks for helping me!
– Ongky Denny Wijaya
Dec 26 '18 at 11:34
add a comment |
By the way, that is multiplication between two octal numbers, not decimal numbers. But, thanks for your help.
– Ongky Denny Wijaya
Dec 24 '18 at 3:36
1
@OngkyDennyWijaya I put online a new version you may enjoy!
– egreg
Dec 24 '18 at 11:30
Best answer! Thanks for helping me!
– Ongky Denny Wijaya
Dec 26 '18 at 11:34
By the way, that is multiplication between two octal numbers, not decimal numbers. But, thanks for your help.
– Ongky Denny Wijaya
Dec 24 '18 at 3:36
By the way, that is multiplication between two octal numbers, not decimal numbers. But, thanks for your help.
– Ongky Denny Wijaya
Dec 24 '18 at 3:36
1
1
@OngkyDennyWijaya I put online a new version you may enjoy!
– egreg
Dec 24 '18 at 11:30
@OngkyDennyWijaya I put online a new version you may enjoy!
– egreg
Dec 24 '18 at 11:30
Best answer! Thanks for helping me!
– Ongky Denny Wijaya
Dec 26 '18 at 11:34
Best answer! Thanks for helping me!
– Ongky Denny Wijaya
Dec 26 '18 at 11:34
add a comment |
TikZ is overkilling here, just simply use multirow
s and cline
s.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
usepackage{multirow}
begin{document}
begin{center}
setlengthtabcolsep{1pt}
begin{tabular}{*{8}{c}}
&&&6&0&0&1\
&&&&2&7&2&multirow{2}{*}[-.2pt]{$times$}\
cline{1-7}
&&1&4&0&0&2\
&5&2&0&0&7&$cdot$\
1&4&0&0&2&$cdot$&$cdot$&multirow{2}{*}[-.2pt]{$+$}\
cline{1-7}
2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
Thanks, for your help
– Ongky Denny Wijaya
Dec 24 '18 at 3:43
@OngkyDennyWijaya You're welcome!
– CarLaTeX
Dec 24 '18 at 4:24
add a comment |
TikZ is overkilling here, just simply use multirow
s and cline
s.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
usepackage{multirow}
begin{document}
begin{center}
setlengthtabcolsep{1pt}
begin{tabular}{*{8}{c}}
&&&6&0&0&1\
&&&&2&7&2&multirow{2}{*}[-.2pt]{$times$}\
cline{1-7}
&&1&4&0&0&2\
&5&2&0&0&7&$cdot$\
1&4&0&0&2&$cdot$&$cdot$&multirow{2}{*}[-.2pt]{$+$}\
cline{1-7}
2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
Thanks, for your help
– Ongky Denny Wijaya
Dec 24 '18 at 3:43
@OngkyDennyWijaya You're welcome!
– CarLaTeX
Dec 24 '18 at 4:24
add a comment |
TikZ is overkilling here, just simply use multirow
s and cline
s.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
usepackage{multirow}
begin{document}
begin{center}
setlengthtabcolsep{1pt}
begin{tabular}{*{8}{c}}
&&&6&0&0&1\
&&&&2&7&2&multirow{2}{*}[-.2pt]{$times$}\
cline{1-7}
&&1&4&0&0&2\
&5&2&0&0&7&$cdot$\
1&4&0&0&2&$cdot$&$cdot$&multirow{2}{*}[-.2pt]{$+$}\
cline{1-7}
2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
TikZ is overkilling here, just simply use multirow
s and cline
s.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
usepackage{multirow}
begin{document}
begin{center}
setlengthtabcolsep{1pt}
begin{tabular}{*{8}{c}}
&&&6&0&0&1\
&&&&2&7&2&multirow{2}{*}[-.2pt]{$times$}\
cline{1-7}
&&1&4&0&0&2\
&5&2&0&0&7&$cdot$\
1&4&0&0&2&$cdot$&$cdot$&multirow{2}{*}[-.2pt]{$+$}\
cline{1-7}
2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
edited Dec 23 '18 at 7:16
answered Dec 23 '18 at 7:11
CarLaTeX
29.9k447127
29.9k447127
Thanks, for your help
– Ongky Denny Wijaya
Dec 24 '18 at 3:43
@OngkyDennyWijaya You're welcome!
– CarLaTeX
Dec 24 '18 at 4:24
add a comment |
Thanks, for your help
– Ongky Denny Wijaya
Dec 24 '18 at 3:43
@OngkyDennyWijaya You're welcome!
– CarLaTeX
Dec 24 '18 at 4:24
Thanks, for your help
– Ongky Denny Wijaya
Dec 24 '18 at 3:43
Thanks, for your help
– Ongky Denny Wijaya
Dec 24 '18 at 3:43
@OngkyDennyWijaya You're welcome!
– CarLaTeX
Dec 24 '18 at 4:24
@OngkyDennyWijaya You're welcome!
– CarLaTeX
Dec 24 '18 at 4:24
add a comment |
Here is a proposal. Decreasing the distance is standard. In order to place the symbols, I am loading TikZ. Loading TikZ for only this may be overkill.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
usepackage{tikz}
usetikzlibrary{tikzmark,calc}
begin{document}
begin{center}
begin{tabular}{*{8}{@{,}c}}
&&&&6&0&0&1\
&&&&&2&7&tikzmarknode{2a}{2}\
hline %$times$
&&&1&4&0&0&tikzmarknode{2b}{2}\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$tikzmarknode{dot}{cdot}$\
hline%$+$
&2&1&3&4&2&7&tikzmarknode{2c}{2}
end{tabular}
begin{tikzpicture}[overlay,remember picture]
node at ([xshift=5mm]$(2a.south)!0.6!(2b.north)$) {$times$};
node at ([xshift=5mm]$(dot.south)!0.6!(2c.north)$) {$+$};
end{tikzpicture}
end{center}
end{document}
2
+1. As a "good housekeeping" measure, maybe also replaceleft=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm
withmargin=2cm
?
– Mico
Dec 23 '18 at 5:46
add a comment |
Here is a proposal. Decreasing the distance is standard. In order to place the symbols, I am loading TikZ. Loading TikZ for only this may be overkill.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
usepackage{tikz}
usetikzlibrary{tikzmark,calc}
begin{document}
begin{center}
begin{tabular}{*{8}{@{,}c}}
&&&&6&0&0&1\
&&&&&2&7&tikzmarknode{2a}{2}\
hline %$times$
&&&1&4&0&0&tikzmarknode{2b}{2}\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$tikzmarknode{dot}{cdot}$\
hline%$+$
&2&1&3&4&2&7&tikzmarknode{2c}{2}
end{tabular}
begin{tikzpicture}[overlay,remember picture]
node at ([xshift=5mm]$(2a.south)!0.6!(2b.north)$) {$times$};
node at ([xshift=5mm]$(dot.south)!0.6!(2c.north)$) {$+$};
end{tikzpicture}
end{center}
end{document}
2
+1. As a "good housekeeping" measure, maybe also replaceleft=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm
withmargin=2cm
?
– Mico
Dec 23 '18 at 5:46
add a comment |
Here is a proposal. Decreasing the distance is standard. In order to place the symbols, I am loading TikZ. Loading TikZ for only this may be overkill.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
usepackage{tikz}
usetikzlibrary{tikzmark,calc}
begin{document}
begin{center}
begin{tabular}{*{8}{@{,}c}}
&&&&6&0&0&1\
&&&&&2&7&tikzmarknode{2a}{2}\
hline %$times$
&&&1&4&0&0&tikzmarknode{2b}{2}\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$tikzmarknode{dot}{cdot}$\
hline%$+$
&2&1&3&4&2&7&tikzmarknode{2c}{2}
end{tabular}
begin{tikzpicture}[overlay,remember picture]
node at ([xshift=5mm]$(2a.south)!0.6!(2b.north)$) {$times$};
node at ([xshift=5mm]$(dot.south)!0.6!(2c.north)$) {$+$};
end{tikzpicture}
end{center}
end{document}
Here is a proposal. Decreasing the distance is standard. In order to place the symbols, I am loading TikZ. Loading TikZ for only this may be overkill.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
usepackage{tikz}
usetikzlibrary{tikzmark,calc}
begin{document}
begin{center}
begin{tabular}{*{8}{@{,}c}}
&&&&6&0&0&1\
&&&&&2&7&tikzmarknode{2a}{2}\
hline %$times$
&&&1&4&0&0&tikzmarknode{2b}{2}\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$tikzmarknode{dot}{cdot}$\
hline%$+$
&2&1&3&4&2&7&tikzmarknode{2c}{2}
end{tabular}
begin{tikzpicture}[overlay,remember picture]
node at ([xshift=5mm]$(2a.south)!0.6!(2b.north)$) {$times$};
node at ([xshift=5mm]$(dot.south)!0.6!(2c.north)$) {$+$};
end{tikzpicture}
end{center}
end{document}
edited Dec 23 '18 at 3:03
answered Dec 23 '18 at 2:03
marmot
88.6k4102190
88.6k4102190
2
+1. As a "good housekeeping" measure, maybe also replaceleft=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm
withmargin=2cm
?
– Mico
Dec 23 '18 at 5:46
add a comment |
2
+1. As a "good housekeeping" measure, maybe also replaceleft=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm
withmargin=2cm
?
– Mico
Dec 23 '18 at 5:46
2
2
+1. As a "good housekeeping" measure, maybe also replace
left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm
with margin=2cm
?– Mico
Dec 23 '18 at 5:46
+1. As a "good housekeeping" measure, maybe also replace
left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm
with margin=2cm
?– Mico
Dec 23 '18 at 5:46
add a comment |
To snug up the numerals, all you need to do is add the instruction setlengthtabcolsep{0pt}
. If the result looks too tight, maybe try setlengthtabcolsep{0.25pt}
.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[margin=2cm]{geometry}
begin{document}
begin{center}
setlengthtabcolsep{0pt} % <-- new
begin{tabular}{cccccccc}
&&&&6&0&0&1\
&&&&&2&7&2\
hline$times$
&&&1&4&0&0&2\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$cdot$\
hline$+$
&2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
for this code, plus and times sign are not in the right of line, but thanks for your answer.
– Ongky Denny Wijaya
Dec 24 '18 at 3:40
add a comment |
To snug up the numerals, all you need to do is add the instruction setlengthtabcolsep{0pt}
. If the result looks too tight, maybe try setlengthtabcolsep{0.25pt}
.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[margin=2cm]{geometry}
begin{document}
begin{center}
setlengthtabcolsep{0pt} % <-- new
begin{tabular}{cccccccc}
&&&&6&0&0&1\
&&&&&2&7&2\
hline$times$
&&&1&4&0&0&2\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$cdot$\
hline$+$
&2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
for this code, plus and times sign are not in the right of line, but thanks for your answer.
– Ongky Denny Wijaya
Dec 24 '18 at 3:40
add a comment |
To snug up the numerals, all you need to do is add the instruction setlengthtabcolsep{0pt}
. If the result looks too tight, maybe try setlengthtabcolsep{0.25pt}
.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[margin=2cm]{geometry}
begin{document}
begin{center}
setlengthtabcolsep{0pt} % <-- new
begin{tabular}{cccccccc}
&&&&6&0&0&1\
&&&&&2&7&2\
hline$times$
&&&1&4&0&0&2\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$cdot$\
hline$+$
&2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
To snug up the numerals, all you need to do is add the instruction setlengthtabcolsep{0pt}
. If the result looks too tight, maybe try setlengthtabcolsep{0.25pt}
.
documentclass[a4paper,12pt,oneside]{letter}
usepackage[margin=2cm]{geometry}
begin{document}
begin{center}
setlengthtabcolsep{0pt} % <-- new
begin{tabular}{cccccccc}
&&&&6&0&0&1\
&&&&&2&7&2\
hline$times$
&&&1&4&0&0&2\
&&5&2&0&0&7&$cdot$\
&1&4&0&0&2&$cdot$&$cdot$\
hline$+$
&2&1&3&4&2&7&2
end{tabular}
end{center}
end{document}
answered Dec 23 '18 at 5:46
Mico
274k30371757
274k30371757
for this code, plus and times sign are not in the right of line, but thanks for your answer.
– Ongky Denny Wijaya
Dec 24 '18 at 3:40
add a comment |
for this code, plus and times sign are not in the right of line, but thanks for your answer.
– Ongky Denny Wijaya
Dec 24 '18 at 3:40
for this code, plus and times sign are not in the right of line, but thanks for your answer.
– Ongky Denny Wijaya
Dec 24 '18 at 3:40
for this code, plus and times sign are not in the right of line, but thanks for your answer.
– Ongky Denny Wijaya
Dec 24 '18 at 3:40
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%2f467054%2fhow-to-put-and-x-after-hline-in-tabular-and-reducing-space%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