How to position text in the top of all columns in the upper row of a table [diagbox]
How can I get '1', '2', '3', '4', and 'Supply' (i.e. the entries in the first row (but in different columns)) on the same height (vertical position) as 'Destination' (i.e. at the top of the columns instead of in the middle of the columns)?
Due to using the 'diagbox' option, the vertical position of these elements is off.
documentclass[12pt,fleqn]{article}
usepackage{pict2e}
usepackage{keyval}
usepackage{calc}
usepackage{fp}
usepackage{diagbox}
usepackage{booktabs}
usepackage{tabularx,colortbl}
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|cccc|c|}
hline
diagbox{textbf{Source}}{textbf{Destination}} & $1$ & $2$ & $3$ & $4$ & textbf{Supply} \
hline
$1$ & $c_{11}$ & $c_{12}$ & $c_{13}$ & $c_{14}$ & $s_1$ \
$2$ & $c_{21}$ & $c_{22}$ & $c_{23}$ & $c_{24}$ & $s_2$ \
$3$ & $c_{31}$ & $c_{32}$ & $c_{33}$ & $c_{34}$ & $s_3$ \
$4$ & $c_{41}$ & $c_{42}$ & $c_{43}$ & $c_{44}$ & $s_4$ \
hline
textbf{Demand} & $d_1$ & $d_2$ & $d_3$ & $d_4$ & $T$\
hline
end{tabular}
end{table}
end{document}
tables diagbox
add a comment |
How can I get '1', '2', '3', '4', and 'Supply' (i.e. the entries in the first row (but in different columns)) on the same height (vertical position) as 'Destination' (i.e. at the top of the columns instead of in the middle of the columns)?
Due to using the 'diagbox' option, the vertical position of these elements is off.
documentclass[12pt,fleqn]{article}
usepackage{pict2e}
usepackage{keyval}
usepackage{calc}
usepackage{fp}
usepackage{diagbox}
usepackage{booktabs}
usepackage{tabularx,colortbl}
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|cccc|c|}
hline
diagbox{textbf{Source}}{textbf{Destination}} & $1$ & $2$ & $3$ & $4$ & textbf{Supply} \
hline
$1$ & $c_{11}$ & $c_{12}$ & $c_{13}$ & $c_{14}$ & $s_1$ \
$2$ & $c_{21}$ & $c_{22}$ & $c_{23}$ & $c_{24}$ & $s_2$ \
$3$ & $c_{31}$ & $c_{32}$ & $c_{33}$ & $c_{34}$ & $s_3$ \
$4$ & $c_{41}$ & $c_{42}$ & $c_{43}$ & $c_{44}$ & $s_4$ \
hline
textbf{Demand} & $d_1$ & $d_2$ & $d_3$ & $d_4$ & $T$\
hline
end{tabular}
end{table}
end{document}
tables diagbox
please be so kind ans extend your code snippet to complete small document, which we can copy and test as it is in our computers! now wee need to gues which package you use for this table etc ...
– Zarko
Dec 1 '18 at 23:38
@Zarko Done, I use relatively many packages so it was kind of difficult to select the useful ones, but I think this represents the problem well.
– Anna
Dec 1 '18 at 23:48
add a comment |
How can I get '1', '2', '3', '4', and 'Supply' (i.e. the entries in the first row (but in different columns)) on the same height (vertical position) as 'Destination' (i.e. at the top of the columns instead of in the middle of the columns)?
Due to using the 'diagbox' option, the vertical position of these elements is off.
documentclass[12pt,fleqn]{article}
usepackage{pict2e}
usepackage{keyval}
usepackage{calc}
usepackage{fp}
usepackage{diagbox}
usepackage{booktabs}
usepackage{tabularx,colortbl}
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|cccc|c|}
hline
diagbox{textbf{Source}}{textbf{Destination}} & $1$ & $2$ & $3$ & $4$ & textbf{Supply} \
hline
$1$ & $c_{11}$ & $c_{12}$ & $c_{13}$ & $c_{14}$ & $s_1$ \
$2$ & $c_{21}$ & $c_{22}$ & $c_{23}$ & $c_{24}$ & $s_2$ \
$3$ & $c_{31}$ & $c_{32}$ & $c_{33}$ & $c_{34}$ & $s_3$ \
$4$ & $c_{41}$ & $c_{42}$ & $c_{43}$ & $c_{44}$ & $s_4$ \
hline
textbf{Demand} & $d_1$ & $d_2$ & $d_3$ & $d_4$ & $T$\
hline
end{tabular}
end{table}
end{document}
tables diagbox
How can I get '1', '2', '3', '4', and 'Supply' (i.e. the entries in the first row (but in different columns)) on the same height (vertical position) as 'Destination' (i.e. at the top of the columns instead of in the middle of the columns)?
Due to using the 'diagbox' option, the vertical position of these elements is off.
documentclass[12pt,fleqn]{article}
usepackage{pict2e}
usepackage{keyval}
usepackage{calc}
usepackage{fp}
usepackage{diagbox}
usepackage{booktabs}
usepackage{tabularx,colortbl}
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|cccc|c|}
hline
diagbox{textbf{Source}}{textbf{Destination}} & $1$ & $2$ & $3$ & $4$ & textbf{Supply} \
hline
$1$ & $c_{11}$ & $c_{12}$ & $c_{13}$ & $c_{14}$ & $s_1$ \
$2$ & $c_{21}$ & $c_{22}$ & $c_{23}$ & $c_{24}$ & $s_2$ \
$3$ & $c_{31}$ & $c_{32}$ & $c_{33}$ & $c_{34}$ & $s_3$ \
$4$ & $c_{41}$ & $c_{42}$ & $c_{43}$ & $c_{44}$ & $s_4$ \
hline
textbf{Demand} & $d_1$ & $d_2$ & $d_3$ & $d_4$ & $T$\
hline
end{tabular}
end{table}
end{document}
tables diagbox
tables diagbox
edited Dec 1 '18 at 23:43
asked Dec 1 '18 at 23:10
Anna
276
276
please be so kind ans extend your code snippet to complete small document, which we can copy and test as it is in our computers! now wee need to gues which package you use for this table etc ...
– Zarko
Dec 1 '18 at 23:38
@Zarko Done, I use relatively many packages so it was kind of difficult to select the useful ones, but I think this represents the problem well.
– Anna
Dec 1 '18 at 23:48
add a comment |
please be so kind ans extend your code snippet to complete small document, which we can copy and test as it is in our computers! now wee need to gues which package you use for this table etc ...
– Zarko
Dec 1 '18 at 23:38
@Zarko Done, I use relatively many packages so it was kind of difficult to select the useful ones, but I think this represents the problem well.
– Anna
Dec 1 '18 at 23:48
please be so kind ans extend your code snippet to complete small document, which we can copy and test as it is in our computers! now wee need to gues which package you use for this table etc ...
– Zarko
Dec 1 '18 at 23:38
please be so kind ans extend your code snippet to complete small document, which we can copy and test as it is in our computers! now wee need to gues which package you use for this table etc ...
– Zarko
Dec 1 '18 at 23:38
@Zarko Done, I use relatively many packages so it was kind of difficult to select the useful ones, but I think this represents the problem well.
– Anna
Dec 1 '18 at 23:48
@Zarko Done, I use relatively many packages so it was kind of difficult to select the useful ones, but I think this represents the problem well.
– Anna
Dec 1 '18 at 23:48
add a comment |
2 Answers
2
active
oldest
votes
meanwhile when you wait on desired solution, see if the following redesign of your table is acceptable to you:
documentclass[12pt,fleqn]{article}
%usepackage{pict2e} % not needed in this mwe
%usepackage{keyval} % not needed in this mwe
%usepackage{calc} % not needed in this mwe
%usepackage{fp} % not needed in this mwe
%usepackage{diagbox} % not needed in this mwe
usepackage{booktabs,
multirow, % <--- new
tabularx} % <--- new
usepackage[table]{xcolor} % <--- changed from colortbl
begin{document}
begin{table}[h!]
caption[short caption]{long caption}
label{tab:table1}
centering
begin{tabular}{*{6}{>{$}c<{$}} }
toprule
multirow{2.4}{*}{textbf{Source}}
& multicolumn{4}{c}{textbf{Destination}}
& multirow{2.4}{*}{textbf{Supply}} \
cmidrule{2-5}
& 1 & 2 & 3 & 4 & \
midrule
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3 & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4 & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
midrule
textbf{Demand}
& d_1 & d_2 & d_3 & d_4 & T \
bottomrule
end{tabular}
end{table}
end{document}
edit: or you more prefer the following solution:
documentclass[12pt,fleqn]{article}
usepackage{diagbox}
usepackage{booktabs,
multirow} % <--- new
usepackage[table]{xcolor} % <--- changed from colortbl
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|cccc|c|}
hline
multirow{2}{*}{
diagbox{textbf{Source}}{textbf{Destination}}
}
& $1$ & $2$ & $3$ & $4$ & textbf{Supply} \
& & & & & \
hline
$1$ & $c_{11}$ & $c_{12}$ & $c_{13}$ & $c_{14}$ & $s_1$ \
$2$ & $c_{21}$ & $c_{22}$ & $c_{23}$ & $c_{24}$ & $s_2$ \
$3$ & $c_{31}$ & $c_{32}$ & $c_{33}$ & $c_{34}$ & $s_3$ \
$4$ & $c_{41}$ & $c_{42}$ & $c_{43}$ & $c_{44}$ & $s_4$ \
hline
textbf{Demand} & $d_1$ & $d_2$ & $d_3$ & $d_4$ & $T$\
hline
end{tabular}
end{table}
end{document}
which gives:
it's probably not difficult to guess which solution I prefer ...
addendum:
according to your new question in the comment below ... if i correctly understood it, than you looking for the following:
in above table for the first column is used column type S
provided by the package siunitx
:
documentclass[12pt,fleqn]{article}
usepackage{booktabs,
multirow} % <--- new
usepackage[table]{xcolor} % <--- instead of colortbl
usepackage{siunitx} % <--- new
begin{document}
begin{table}[h!]
caption[short caption]{long caption}
label{tab:table1}
centering
begin{tabular}{S[table-format=1.0,
table-space-text-post={*}] % <--- new
*{5}{>{$}c<{$}}
}
toprule
{multirow{2.4}{*}{textbf{Source}}}
& multicolumn{4}{c}{textbf{Destination}}
& multirow{2.4}{*}{textbf{Supply}} \
cmidrule{2-5}
& 1 & 2 & 3^* & 4^ast & \ % two cases how to write *
midrule
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3* & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4* & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
midrule
textbf{Demand}
& d_1 & d_2 & d_3 & d_4 & T \
bottomrule
end{tabular}
end{table}
end{document}
in the case that *
is intended to write some notes in table, than may the threeparttable
can help you in this.
The first table is absolutely beautiful. Yeah, I think I'll go for that one, since it looks definitely better than what I first intended. Thank you.
– Anna
Dec 2 '18 at 12:40
One small question remaining though: I have to include a subscript star (*) to 3 and 4 but that results in a 1 and 2 at the position of the star (center-right aligned) instead of at the position of 3 and 4 (center-left aligned). How can I fix that?
– Anna
Dec 2 '18 at 13:03
@Anna, sorry, i not understand you. can you write as math expression, what is your problem, i.e. if instead of 3 and 4 you like to have 3_{} and 4_{ }(3_{ast} and 4_{ast})? if you wrote so, where you expect position of star? as 3ast?
– Zarko
Dec 2 '18 at 13:35
I have 3^{ast} and 4^{ast} instead of just 3 and 4. 1 and 2 are without superscript *. If you run the code you see that 1 and 2 are then not positioned nicely, i.e. 1 and 2 are above the *'s of 3 and 4 but not right above the actual numbers as they should be (that's what I meant with center-left aligned vs center-right aligned).
– Anna
Dec 2 '18 at 14:22
i guess that you talking about positioning of numbers in the first column. they are horizontal centered but you like to have numbers to be right aligned and * should bi right of numbers. do i'm right? for this the column type should be changed. an example i will prepare asap.
– Zarko
Dec 2 '18 at 14:40
|
show 2 more comments
It is quite possible with some raisebox
es, but I don't think it's so nice:
documentclass[12pt,fleqn]{article}
usepackage{pict2e}
usepackage{keyval}
usepackage{calc}
usepackage{fp}
usepackage{diagbox}
usepackage{booktabs}
usepackage{tabularx,colortbl, makecell, caption}
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|*{4}{>{$}c<{$}}|>{$}c<{$}|}
hline
diagbox[innerwidth =40mm, height =15mm]%,innerleftsep = 12pt
{raisebox{2.5ex}{textbf{Source}}}{raisebox{-0.5ex}{textbf{Destination}}} & raisebox{2.25ex}{$1$} & raisebox{2.25ex}{$2$} & raisebox{2.25ex}{$3$} & raisebox{2.25ex}{$4$} & raisebox{2.25ex}{textbf{Supply}} \
hline
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3 & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4 & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
hline
textbf{Demand} & d_1 & d_2 & d_3 & d_4 & T\
hline
end{tabular}
end{table}
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%2f462761%2fhow-to-position-text-in-the-top-of-all-columns-in-the-upper-row-of-a-table-diag%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
meanwhile when you wait on desired solution, see if the following redesign of your table is acceptable to you:
documentclass[12pt,fleqn]{article}
%usepackage{pict2e} % not needed in this mwe
%usepackage{keyval} % not needed in this mwe
%usepackage{calc} % not needed in this mwe
%usepackage{fp} % not needed in this mwe
%usepackage{diagbox} % not needed in this mwe
usepackage{booktabs,
multirow, % <--- new
tabularx} % <--- new
usepackage[table]{xcolor} % <--- changed from colortbl
begin{document}
begin{table}[h!]
caption[short caption]{long caption}
label{tab:table1}
centering
begin{tabular}{*{6}{>{$}c<{$}} }
toprule
multirow{2.4}{*}{textbf{Source}}
& multicolumn{4}{c}{textbf{Destination}}
& multirow{2.4}{*}{textbf{Supply}} \
cmidrule{2-5}
& 1 & 2 & 3 & 4 & \
midrule
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3 & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4 & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
midrule
textbf{Demand}
& d_1 & d_2 & d_3 & d_4 & T \
bottomrule
end{tabular}
end{table}
end{document}
edit: or you more prefer the following solution:
documentclass[12pt,fleqn]{article}
usepackage{diagbox}
usepackage{booktabs,
multirow} % <--- new
usepackage[table]{xcolor} % <--- changed from colortbl
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|cccc|c|}
hline
multirow{2}{*}{
diagbox{textbf{Source}}{textbf{Destination}}
}
& $1$ & $2$ & $3$ & $4$ & textbf{Supply} \
& & & & & \
hline
$1$ & $c_{11}$ & $c_{12}$ & $c_{13}$ & $c_{14}$ & $s_1$ \
$2$ & $c_{21}$ & $c_{22}$ & $c_{23}$ & $c_{24}$ & $s_2$ \
$3$ & $c_{31}$ & $c_{32}$ & $c_{33}$ & $c_{34}$ & $s_3$ \
$4$ & $c_{41}$ & $c_{42}$ & $c_{43}$ & $c_{44}$ & $s_4$ \
hline
textbf{Demand} & $d_1$ & $d_2$ & $d_3$ & $d_4$ & $T$\
hline
end{tabular}
end{table}
end{document}
which gives:
it's probably not difficult to guess which solution I prefer ...
addendum:
according to your new question in the comment below ... if i correctly understood it, than you looking for the following:
in above table for the first column is used column type S
provided by the package siunitx
:
documentclass[12pt,fleqn]{article}
usepackage{booktabs,
multirow} % <--- new
usepackage[table]{xcolor} % <--- instead of colortbl
usepackage{siunitx} % <--- new
begin{document}
begin{table}[h!]
caption[short caption]{long caption}
label{tab:table1}
centering
begin{tabular}{S[table-format=1.0,
table-space-text-post={*}] % <--- new
*{5}{>{$}c<{$}}
}
toprule
{multirow{2.4}{*}{textbf{Source}}}
& multicolumn{4}{c}{textbf{Destination}}
& multirow{2.4}{*}{textbf{Supply}} \
cmidrule{2-5}
& 1 & 2 & 3^* & 4^ast & \ % two cases how to write *
midrule
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3* & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4* & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
midrule
textbf{Demand}
& d_1 & d_2 & d_3 & d_4 & T \
bottomrule
end{tabular}
end{table}
end{document}
in the case that *
is intended to write some notes in table, than may the threeparttable
can help you in this.
The first table is absolutely beautiful. Yeah, I think I'll go for that one, since it looks definitely better than what I first intended. Thank you.
– Anna
Dec 2 '18 at 12:40
One small question remaining though: I have to include a subscript star (*) to 3 and 4 but that results in a 1 and 2 at the position of the star (center-right aligned) instead of at the position of 3 and 4 (center-left aligned). How can I fix that?
– Anna
Dec 2 '18 at 13:03
@Anna, sorry, i not understand you. can you write as math expression, what is your problem, i.e. if instead of 3 and 4 you like to have 3_{} and 4_{ }(3_{ast} and 4_{ast})? if you wrote so, where you expect position of star? as 3ast?
– Zarko
Dec 2 '18 at 13:35
I have 3^{ast} and 4^{ast} instead of just 3 and 4. 1 and 2 are without superscript *. If you run the code you see that 1 and 2 are then not positioned nicely, i.e. 1 and 2 are above the *'s of 3 and 4 but not right above the actual numbers as they should be (that's what I meant with center-left aligned vs center-right aligned).
– Anna
Dec 2 '18 at 14:22
i guess that you talking about positioning of numbers in the first column. they are horizontal centered but you like to have numbers to be right aligned and * should bi right of numbers. do i'm right? for this the column type should be changed. an example i will prepare asap.
– Zarko
Dec 2 '18 at 14:40
|
show 2 more comments
meanwhile when you wait on desired solution, see if the following redesign of your table is acceptable to you:
documentclass[12pt,fleqn]{article}
%usepackage{pict2e} % not needed in this mwe
%usepackage{keyval} % not needed in this mwe
%usepackage{calc} % not needed in this mwe
%usepackage{fp} % not needed in this mwe
%usepackage{diagbox} % not needed in this mwe
usepackage{booktabs,
multirow, % <--- new
tabularx} % <--- new
usepackage[table]{xcolor} % <--- changed from colortbl
begin{document}
begin{table}[h!]
caption[short caption]{long caption}
label{tab:table1}
centering
begin{tabular}{*{6}{>{$}c<{$}} }
toprule
multirow{2.4}{*}{textbf{Source}}
& multicolumn{4}{c}{textbf{Destination}}
& multirow{2.4}{*}{textbf{Supply}} \
cmidrule{2-5}
& 1 & 2 & 3 & 4 & \
midrule
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3 & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4 & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
midrule
textbf{Demand}
& d_1 & d_2 & d_3 & d_4 & T \
bottomrule
end{tabular}
end{table}
end{document}
edit: or you more prefer the following solution:
documentclass[12pt,fleqn]{article}
usepackage{diagbox}
usepackage{booktabs,
multirow} % <--- new
usepackage[table]{xcolor} % <--- changed from colortbl
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|cccc|c|}
hline
multirow{2}{*}{
diagbox{textbf{Source}}{textbf{Destination}}
}
& $1$ & $2$ & $3$ & $4$ & textbf{Supply} \
& & & & & \
hline
$1$ & $c_{11}$ & $c_{12}$ & $c_{13}$ & $c_{14}$ & $s_1$ \
$2$ & $c_{21}$ & $c_{22}$ & $c_{23}$ & $c_{24}$ & $s_2$ \
$3$ & $c_{31}$ & $c_{32}$ & $c_{33}$ & $c_{34}$ & $s_3$ \
$4$ & $c_{41}$ & $c_{42}$ & $c_{43}$ & $c_{44}$ & $s_4$ \
hline
textbf{Demand} & $d_1$ & $d_2$ & $d_3$ & $d_4$ & $T$\
hline
end{tabular}
end{table}
end{document}
which gives:
it's probably not difficult to guess which solution I prefer ...
addendum:
according to your new question in the comment below ... if i correctly understood it, than you looking for the following:
in above table for the first column is used column type S
provided by the package siunitx
:
documentclass[12pt,fleqn]{article}
usepackage{booktabs,
multirow} % <--- new
usepackage[table]{xcolor} % <--- instead of colortbl
usepackage{siunitx} % <--- new
begin{document}
begin{table}[h!]
caption[short caption]{long caption}
label{tab:table1}
centering
begin{tabular}{S[table-format=1.0,
table-space-text-post={*}] % <--- new
*{5}{>{$}c<{$}}
}
toprule
{multirow{2.4}{*}{textbf{Source}}}
& multicolumn{4}{c}{textbf{Destination}}
& multirow{2.4}{*}{textbf{Supply}} \
cmidrule{2-5}
& 1 & 2 & 3^* & 4^ast & \ % two cases how to write *
midrule
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3* & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4* & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
midrule
textbf{Demand}
& d_1 & d_2 & d_3 & d_4 & T \
bottomrule
end{tabular}
end{table}
end{document}
in the case that *
is intended to write some notes in table, than may the threeparttable
can help you in this.
The first table is absolutely beautiful. Yeah, I think I'll go for that one, since it looks definitely better than what I first intended. Thank you.
– Anna
Dec 2 '18 at 12:40
One small question remaining though: I have to include a subscript star (*) to 3 and 4 but that results in a 1 and 2 at the position of the star (center-right aligned) instead of at the position of 3 and 4 (center-left aligned). How can I fix that?
– Anna
Dec 2 '18 at 13:03
@Anna, sorry, i not understand you. can you write as math expression, what is your problem, i.e. if instead of 3 and 4 you like to have 3_{} and 4_{ }(3_{ast} and 4_{ast})? if you wrote so, where you expect position of star? as 3ast?
– Zarko
Dec 2 '18 at 13:35
I have 3^{ast} and 4^{ast} instead of just 3 and 4. 1 and 2 are without superscript *. If you run the code you see that 1 and 2 are then not positioned nicely, i.e. 1 and 2 are above the *'s of 3 and 4 but not right above the actual numbers as they should be (that's what I meant with center-left aligned vs center-right aligned).
– Anna
Dec 2 '18 at 14:22
i guess that you talking about positioning of numbers in the first column. they are horizontal centered but you like to have numbers to be right aligned and * should bi right of numbers. do i'm right? for this the column type should be changed. an example i will prepare asap.
– Zarko
Dec 2 '18 at 14:40
|
show 2 more comments
meanwhile when you wait on desired solution, see if the following redesign of your table is acceptable to you:
documentclass[12pt,fleqn]{article}
%usepackage{pict2e} % not needed in this mwe
%usepackage{keyval} % not needed in this mwe
%usepackage{calc} % not needed in this mwe
%usepackage{fp} % not needed in this mwe
%usepackage{diagbox} % not needed in this mwe
usepackage{booktabs,
multirow, % <--- new
tabularx} % <--- new
usepackage[table]{xcolor} % <--- changed from colortbl
begin{document}
begin{table}[h!]
caption[short caption]{long caption}
label{tab:table1}
centering
begin{tabular}{*{6}{>{$}c<{$}} }
toprule
multirow{2.4}{*}{textbf{Source}}
& multicolumn{4}{c}{textbf{Destination}}
& multirow{2.4}{*}{textbf{Supply}} \
cmidrule{2-5}
& 1 & 2 & 3 & 4 & \
midrule
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3 & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4 & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
midrule
textbf{Demand}
& d_1 & d_2 & d_3 & d_4 & T \
bottomrule
end{tabular}
end{table}
end{document}
edit: or you more prefer the following solution:
documentclass[12pt,fleqn]{article}
usepackage{diagbox}
usepackage{booktabs,
multirow} % <--- new
usepackage[table]{xcolor} % <--- changed from colortbl
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|cccc|c|}
hline
multirow{2}{*}{
diagbox{textbf{Source}}{textbf{Destination}}
}
& $1$ & $2$ & $3$ & $4$ & textbf{Supply} \
& & & & & \
hline
$1$ & $c_{11}$ & $c_{12}$ & $c_{13}$ & $c_{14}$ & $s_1$ \
$2$ & $c_{21}$ & $c_{22}$ & $c_{23}$ & $c_{24}$ & $s_2$ \
$3$ & $c_{31}$ & $c_{32}$ & $c_{33}$ & $c_{34}$ & $s_3$ \
$4$ & $c_{41}$ & $c_{42}$ & $c_{43}$ & $c_{44}$ & $s_4$ \
hline
textbf{Demand} & $d_1$ & $d_2$ & $d_3$ & $d_4$ & $T$\
hline
end{tabular}
end{table}
end{document}
which gives:
it's probably not difficult to guess which solution I prefer ...
addendum:
according to your new question in the comment below ... if i correctly understood it, than you looking for the following:
in above table for the first column is used column type S
provided by the package siunitx
:
documentclass[12pt,fleqn]{article}
usepackage{booktabs,
multirow} % <--- new
usepackage[table]{xcolor} % <--- instead of colortbl
usepackage{siunitx} % <--- new
begin{document}
begin{table}[h!]
caption[short caption]{long caption}
label{tab:table1}
centering
begin{tabular}{S[table-format=1.0,
table-space-text-post={*}] % <--- new
*{5}{>{$}c<{$}}
}
toprule
{multirow{2.4}{*}{textbf{Source}}}
& multicolumn{4}{c}{textbf{Destination}}
& multirow{2.4}{*}{textbf{Supply}} \
cmidrule{2-5}
& 1 & 2 & 3^* & 4^ast & \ % two cases how to write *
midrule
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3* & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4* & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
midrule
textbf{Demand}
& d_1 & d_2 & d_3 & d_4 & T \
bottomrule
end{tabular}
end{table}
end{document}
in the case that *
is intended to write some notes in table, than may the threeparttable
can help you in this.
meanwhile when you wait on desired solution, see if the following redesign of your table is acceptable to you:
documentclass[12pt,fleqn]{article}
%usepackage{pict2e} % not needed in this mwe
%usepackage{keyval} % not needed in this mwe
%usepackage{calc} % not needed in this mwe
%usepackage{fp} % not needed in this mwe
%usepackage{diagbox} % not needed in this mwe
usepackage{booktabs,
multirow, % <--- new
tabularx} % <--- new
usepackage[table]{xcolor} % <--- changed from colortbl
begin{document}
begin{table}[h!]
caption[short caption]{long caption}
label{tab:table1}
centering
begin{tabular}{*{6}{>{$}c<{$}} }
toprule
multirow{2.4}{*}{textbf{Source}}
& multicolumn{4}{c}{textbf{Destination}}
& multirow{2.4}{*}{textbf{Supply}} \
cmidrule{2-5}
& 1 & 2 & 3 & 4 & \
midrule
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3 & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4 & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
midrule
textbf{Demand}
& d_1 & d_2 & d_3 & d_4 & T \
bottomrule
end{tabular}
end{table}
end{document}
edit: or you more prefer the following solution:
documentclass[12pt,fleqn]{article}
usepackage{diagbox}
usepackage{booktabs,
multirow} % <--- new
usepackage[table]{xcolor} % <--- changed from colortbl
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|cccc|c|}
hline
multirow{2}{*}{
diagbox{textbf{Source}}{textbf{Destination}}
}
& $1$ & $2$ & $3$ & $4$ & textbf{Supply} \
& & & & & \
hline
$1$ & $c_{11}$ & $c_{12}$ & $c_{13}$ & $c_{14}$ & $s_1$ \
$2$ & $c_{21}$ & $c_{22}$ & $c_{23}$ & $c_{24}$ & $s_2$ \
$3$ & $c_{31}$ & $c_{32}$ & $c_{33}$ & $c_{34}$ & $s_3$ \
$4$ & $c_{41}$ & $c_{42}$ & $c_{43}$ & $c_{44}$ & $s_4$ \
hline
textbf{Demand} & $d_1$ & $d_2$ & $d_3$ & $d_4$ & $T$\
hline
end{tabular}
end{table}
end{document}
which gives:
it's probably not difficult to guess which solution I prefer ...
addendum:
according to your new question in the comment below ... if i correctly understood it, than you looking for the following:
in above table for the first column is used column type S
provided by the package siunitx
:
documentclass[12pt,fleqn]{article}
usepackage{booktabs,
multirow} % <--- new
usepackage[table]{xcolor} % <--- instead of colortbl
usepackage{siunitx} % <--- new
begin{document}
begin{table}[h!]
caption[short caption]{long caption}
label{tab:table1}
centering
begin{tabular}{S[table-format=1.0,
table-space-text-post={*}] % <--- new
*{5}{>{$}c<{$}}
}
toprule
{multirow{2.4}{*}{textbf{Source}}}
& multicolumn{4}{c}{textbf{Destination}}
& multirow{2.4}{*}{textbf{Supply}} \
cmidrule{2-5}
& 1 & 2 & 3^* & 4^ast & \ % two cases how to write *
midrule
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3* & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4* & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
midrule
textbf{Demand}
& d_1 & d_2 & d_3 & d_4 & T \
bottomrule
end{tabular}
end{table}
end{document}
in the case that *
is intended to write some notes in table, than may the threeparttable
can help you in this.
edited Dec 2 '18 at 14:58
answered Dec 2 '18 at 0:37
Zarko
121k865156
121k865156
The first table is absolutely beautiful. Yeah, I think I'll go for that one, since it looks definitely better than what I first intended. Thank you.
– Anna
Dec 2 '18 at 12:40
One small question remaining though: I have to include a subscript star (*) to 3 and 4 but that results in a 1 and 2 at the position of the star (center-right aligned) instead of at the position of 3 and 4 (center-left aligned). How can I fix that?
– Anna
Dec 2 '18 at 13:03
@Anna, sorry, i not understand you. can you write as math expression, what is your problem, i.e. if instead of 3 and 4 you like to have 3_{} and 4_{ }(3_{ast} and 4_{ast})? if you wrote so, where you expect position of star? as 3ast?
– Zarko
Dec 2 '18 at 13:35
I have 3^{ast} and 4^{ast} instead of just 3 and 4. 1 and 2 are without superscript *. If you run the code you see that 1 and 2 are then not positioned nicely, i.e. 1 and 2 are above the *'s of 3 and 4 but not right above the actual numbers as they should be (that's what I meant with center-left aligned vs center-right aligned).
– Anna
Dec 2 '18 at 14:22
i guess that you talking about positioning of numbers in the first column. they are horizontal centered but you like to have numbers to be right aligned and * should bi right of numbers. do i'm right? for this the column type should be changed. an example i will prepare asap.
– Zarko
Dec 2 '18 at 14:40
|
show 2 more comments
The first table is absolutely beautiful. Yeah, I think I'll go for that one, since it looks definitely better than what I first intended. Thank you.
– Anna
Dec 2 '18 at 12:40
One small question remaining though: I have to include a subscript star (*) to 3 and 4 but that results in a 1 and 2 at the position of the star (center-right aligned) instead of at the position of 3 and 4 (center-left aligned). How can I fix that?
– Anna
Dec 2 '18 at 13:03
@Anna, sorry, i not understand you. can you write as math expression, what is your problem, i.e. if instead of 3 and 4 you like to have 3_{} and 4_{ }(3_{ast} and 4_{ast})? if you wrote so, where you expect position of star? as 3ast?
– Zarko
Dec 2 '18 at 13:35
I have 3^{ast} and 4^{ast} instead of just 3 and 4. 1 and 2 are without superscript *. If you run the code you see that 1 and 2 are then not positioned nicely, i.e. 1 and 2 are above the *'s of 3 and 4 but not right above the actual numbers as they should be (that's what I meant with center-left aligned vs center-right aligned).
– Anna
Dec 2 '18 at 14:22
i guess that you talking about positioning of numbers in the first column. they are horizontal centered but you like to have numbers to be right aligned and * should bi right of numbers. do i'm right? for this the column type should be changed. an example i will prepare asap.
– Zarko
Dec 2 '18 at 14:40
The first table is absolutely beautiful. Yeah, I think I'll go for that one, since it looks definitely better than what I first intended. Thank you.
– Anna
Dec 2 '18 at 12:40
The first table is absolutely beautiful. Yeah, I think I'll go for that one, since it looks definitely better than what I first intended. Thank you.
– Anna
Dec 2 '18 at 12:40
One small question remaining though: I have to include a subscript star (*) to 3 and 4 but that results in a 1 and 2 at the position of the star (center-right aligned) instead of at the position of 3 and 4 (center-left aligned). How can I fix that?
– Anna
Dec 2 '18 at 13:03
One small question remaining though: I have to include a subscript star (*) to 3 and 4 but that results in a 1 and 2 at the position of the star (center-right aligned) instead of at the position of 3 and 4 (center-left aligned). How can I fix that?
– Anna
Dec 2 '18 at 13:03
@Anna, sorry, i not understand you. can you write as math expression, what is your problem, i.e. if instead of 3 and 4 you like to have 3_{} and 4_{ }(3_{ast} and 4_{ast})? if you wrote so, where you expect position of star? as 3ast?
– Zarko
Dec 2 '18 at 13:35
@Anna, sorry, i not understand you. can you write as math expression, what is your problem, i.e. if instead of 3 and 4 you like to have 3_{} and 4_{ }(3_{ast} and 4_{ast})? if you wrote so, where you expect position of star? as 3ast?
– Zarko
Dec 2 '18 at 13:35
I have 3^{ast} and 4^{ast} instead of just 3 and 4. 1 and 2 are without superscript *. If you run the code you see that 1 and 2 are then not positioned nicely, i.e. 1 and 2 are above the *'s of 3 and 4 but not right above the actual numbers as they should be (that's what I meant with center-left aligned vs center-right aligned).
– Anna
Dec 2 '18 at 14:22
I have 3^{ast} and 4^{ast} instead of just 3 and 4. 1 and 2 are without superscript *. If you run the code you see that 1 and 2 are then not positioned nicely, i.e. 1 and 2 are above the *'s of 3 and 4 but not right above the actual numbers as they should be (that's what I meant with center-left aligned vs center-right aligned).
– Anna
Dec 2 '18 at 14:22
i guess that you talking about positioning of numbers in the first column. they are horizontal centered but you like to have numbers to be right aligned and * should bi right of numbers. do i'm right? for this the column type should be changed. an example i will prepare asap.
– Zarko
Dec 2 '18 at 14:40
i guess that you talking about positioning of numbers in the first column. they are horizontal centered but you like to have numbers to be right aligned and * should bi right of numbers. do i'm right? for this the column type should be changed. an example i will prepare asap.
– Zarko
Dec 2 '18 at 14:40
|
show 2 more comments
It is quite possible with some raisebox
es, but I don't think it's so nice:
documentclass[12pt,fleqn]{article}
usepackage{pict2e}
usepackage{keyval}
usepackage{calc}
usepackage{fp}
usepackage{diagbox}
usepackage{booktabs}
usepackage{tabularx,colortbl, makecell, caption}
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|*{4}{>{$}c<{$}}|>{$}c<{$}|}
hline
diagbox[innerwidth =40mm, height =15mm]%,innerleftsep = 12pt
{raisebox{2.5ex}{textbf{Source}}}{raisebox{-0.5ex}{textbf{Destination}}} & raisebox{2.25ex}{$1$} & raisebox{2.25ex}{$2$} & raisebox{2.25ex}{$3$} & raisebox{2.25ex}{$4$} & raisebox{2.25ex}{textbf{Supply}} \
hline
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3 & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4 & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
hline
textbf{Demand} & d_1 & d_2 & d_3 & d_4 & T\
hline
end{tabular}
end{table}
end{document}
add a comment |
It is quite possible with some raisebox
es, but I don't think it's so nice:
documentclass[12pt,fleqn]{article}
usepackage{pict2e}
usepackage{keyval}
usepackage{calc}
usepackage{fp}
usepackage{diagbox}
usepackage{booktabs}
usepackage{tabularx,colortbl, makecell, caption}
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|*{4}{>{$}c<{$}}|>{$}c<{$}|}
hline
diagbox[innerwidth =40mm, height =15mm]%,innerleftsep = 12pt
{raisebox{2.5ex}{textbf{Source}}}{raisebox{-0.5ex}{textbf{Destination}}} & raisebox{2.25ex}{$1$} & raisebox{2.25ex}{$2$} & raisebox{2.25ex}{$3$} & raisebox{2.25ex}{$4$} & raisebox{2.25ex}{textbf{Supply}} \
hline
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3 & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4 & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
hline
textbf{Demand} & d_1 & d_2 & d_3 & d_4 & T\
hline
end{tabular}
end{table}
end{document}
add a comment |
It is quite possible with some raisebox
es, but I don't think it's so nice:
documentclass[12pt,fleqn]{article}
usepackage{pict2e}
usepackage{keyval}
usepackage{calc}
usepackage{fp}
usepackage{diagbox}
usepackage{booktabs}
usepackage{tabularx,colortbl, makecell, caption}
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|*{4}{>{$}c<{$}}|>{$}c<{$}|}
hline
diagbox[innerwidth =40mm, height =15mm]%,innerleftsep = 12pt
{raisebox{2.5ex}{textbf{Source}}}{raisebox{-0.5ex}{textbf{Destination}}} & raisebox{2.25ex}{$1$} & raisebox{2.25ex}{$2$} & raisebox{2.25ex}{$3$} & raisebox{2.25ex}{$4$} & raisebox{2.25ex}{textbf{Supply}} \
hline
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3 & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4 & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
hline
textbf{Demand} & d_1 & d_2 & d_3 & d_4 & T\
hline
end{tabular}
end{table}
end{document}
It is quite possible with some raisebox
es, but I don't think it's so nice:
documentclass[12pt,fleqn]{article}
usepackage{pict2e}
usepackage{keyval}
usepackage{calc}
usepackage{fp}
usepackage{diagbox}
usepackage{booktabs}
usepackage{tabularx,colortbl, makecell, caption}
begin{document}
begin{table}[h!]
centering
caption[caption]{Table 1}
label{tab:table1}
begin{tabular}{|l|*{4}{>{$}c<{$}}|>{$}c<{$}|}
hline
diagbox[innerwidth =40mm, height =15mm]%,innerleftsep = 12pt
{raisebox{2.5ex}{textbf{Source}}}{raisebox{-0.5ex}{textbf{Destination}}} & raisebox{2.25ex}{$1$} & raisebox{2.25ex}{$2$} & raisebox{2.25ex}{$3$} & raisebox{2.25ex}{$4$} & raisebox{2.25ex}{textbf{Supply}} \
hline
1 & c_{11} & c_{12} & c_{13} & c_{14} & s_1 \
2 & c_{21} & c_{22} & c_{23} & c_{24} & s_2 \
3 & c_{31} & c_{32} & c_{33} & c_{34} & s_3 \
4 & c_{41} & c_{42} & c_{43} & c_{44} & s_4 \
hline
textbf{Demand} & d_1 & d_2 & d_3 & d_4 & T\
hline
end{tabular}
end{table}
end{document}
answered Dec 2 '18 at 0:41
Bernard
166k769194
166k769194
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%2f462761%2fhow-to-position-text-in-the-top-of-all-columns-in-the-upper-row-of-a-table-diag%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
please be so kind ans extend your code snippet to complete small document, which we can copy and test as it is in our computers! now wee need to gues which package you use for this table etc ...
– Zarko
Dec 1 '18 at 23:38
@Zarko Done, I use relatively many packages so it was kind of difficult to select the useful ones, but I think this represents the problem well.
– Anna
Dec 1 '18 at 23:48