How to define a variable as another variable divided by two?
up vote
5
down vote
favorite
I would like to define a variable j
in a loop foreach i in { 2, 4, 6}
and use j
to labels of the nodes.
Here is my code:
documentclass{standalone}
usepackage{balance,complexity,pgfplots,tikz,tikz-3dplot}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[scale=0.4]
def half {0.5};
foreach i in { 2, 4, 6}
{
def j {i*half};
node[draw=none] at (i,0) {$X_{j}$};
node[draw=none] at (-i,0) {$X'_{j}$};
}
end{tikzpicture}
end{document}
I would like to get this output:
Instead, I get this:
How can I use mathematical operators to modify the label of a node?
tikz-pgf calc
add a comment |
up vote
5
down vote
favorite
I would like to define a variable j
in a loop foreach i in { 2, 4, 6}
and use j
to labels of the nodes.
Here is my code:
documentclass{standalone}
usepackage{balance,complexity,pgfplots,tikz,tikz-3dplot}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[scale=0.4]
def half {0.5};
foreach i in { 2, 4, 6}
{
def j {i*half};
node[draw=none] at (i,0) {$X_{j}$};
node[draw=none] at (-i,0) {$X'_{j}$};
}
end{tikzpicture}
end{document}
I would like to get this output:
Instead, I get this:
How can I use mathematical operators to modify the label of a node?
tikz-pgf calc
Isn't it easier doingnode[draw=none] at (2*i,0) {$X_{i}$};
withforeach i in {1,2,3}
?
– egreg
Nov 11 at 14:52
@egreg That is true, but I need the division or multiplication by 0.5 for a different reason.
– padawan
Nov 11 at 14:53
@egreg I just realized that I could also use the method that you suggested :)
– padawan
Nov 11 at 22:20
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I would like to define a variable j
in a loop foreach i in { 2, 4, 6}
and use j
to labels of the nodes.
Here is my code:
documentclass{standalone}
usepackage{balance,complexity,pgfplots,tikz,tikz-3dplot}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[scale=0.4]
def half {0.5};
foreach i in { 2, 4, 6}
{
def j {i*half};
node[draw=none] at (i,0) {$X_{j}$};
node[draw=none] at (-i,0) {$X'_{j}$};
}
end{tikzpicture}
end{document}
I would like to get this output:
Instead, I get this:
How can I use mathematical operators to modify the label of a node?
tikz-pgf calc
I would like to define a variable j
in a loop foreach i in { 2, 4, 6}
and use j
to labels of the nodes.
Here is my code:
documentclass{standalone}
usepackage{balance,complexity,pgfplots,tikz,tikz-3dplot}
usetikzlibrary{calc}
begin{document}
begin{tikzpicture}[scale=0.4]
def half {0.5};
foreach i in { 2, 4, 6}
{
def j {i*half};
node[draw=none] at (i,0) {$X_{j}$};
node[draw=none] at (-i,0) {$X'_{j}$};
}
end{tikzpicture}
end{document}
I would like to get this output:
Instead, I get this:
How can I use mathematical operators to modify the label of a node?
tikz-pgf calc
tikz-pgf calc
asked Nov 11 at 14:46
padawan
559518
559518
Isn't it easier doingnode[draw=none] at (2*i,0) {$X_{i}$};
withforeach i in {1,2,3}
?
– egreg
Nov 11 at 14:52
@egreg That is true, but I need the division or multiplication by 0.5 for a different reason.
– padawan
Nov 11 at 14:53
@egreg I just realized that I could also use the method that you suggested :)
– padawan
Nov 11 at 22:20
add a comment |
Isn't it easier doingnode[draw=none] at (2*i,0) {$X_{i}$};
withforeach i in {1,2,3}
?
– egreg
Nov 11 at 14:52
@egreg That is true, but I need the division or multiplication by 0.5 for a different reason.
– padawan
Nov 11 at 14:53
@egreg I just realized that I could also use the method that you suggested :)
– padawan
Nov 11 at 22:20
Isn't it easier doing
node[draw=none] at (2*i,0) {$X_{i}$};
with foreach i in {1,2,3}
?– egreg
Nov 11 at 14:52
Isn't it easier doing
node[draw=none] at (2*i,0) {$X_{i}$};
with foreach i in {1,2,3}
?– egreg
Nov 11 at 14:52
@egreg That is true, but I need the division or multiplication by 0.5 for a different reason.
– padawan
Nov 11 at 14:53
@egreg That is true, but I need the division or multiplication by 0.5 for a different reason.
– padawan
Nov 11 at 14:53
@egreg I just realized that I could also use the method that you suggested :)
– padawan
Nov 11 at 22:20
@egreg I just realized that I could also use the method that you suggested :)
– padawan
Nov 11 at 22:20
add a comment |
2 Answers
2
active
oldest
votes
up vote
7
down vote
accepted
Use the pgfmath
macros (pgfmathsetmacro
for float calculations and pgfmathtruncatemacro
if you only want the integer part).
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=0.4]
pgfmathsetmacrohalf {0.5};
foreach i in { 2, 4, 6}
{
pgfmathtruncatemacroj{i*half};
node[draw=none] at (i,0) {$X_{j}$};
node[draw=none] at (-i,0) {$X'_{j}$};
}
end{tikzpicture}
end{document}
add a comment |
up vote
7
down vote
You can do the calculations within the foreach
loop with
foreach i [evaluate=i as moitie using int(i/2)] in { 2, 4, 6}
see page 904 of manual 3.0.1a.
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=0.4]
foreach i [evaluate=i as moitie using int(i/2)] in { 2, 4, 6}
{
node[draw=none] at (i,0) {$X_{moitie}$};
node[draw=none] at (-i,0) {$X'_{moitie}$};
}
end{tikzpicture}
end{document}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
Use the pgfmath
macros (pgfmathsetmacro
for float calculations and pgfmathtruncatemacro
if you only want the integer part).
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=0.4]
pgfmathsetmacrohalf {0.5};
foreach i in { 2, 4, 6}
{
pgfmathtruncatemacroj{i*half};
node[draw=none] at (i,0) {$X_{j}$};
node[draw=none] at (-i,0) {$X'_{j}$};
}
end{tikzpicture}
end{document}
add a comment |
up vote
7
down vote
accepted
Use the pgfmath
macros (pgfmathsetmacro
for float calculations and pgfmathtruncatemacro
if you only want the integer part).
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=0.4]
pgfmathsetmacrohalf {0.5};
foreach i in { 2, 4, 6}
{
pgfmathtruncatemacroj{i*half};
node[draw=none] at (i,0) {$X_{j}$};
node[draw=none] at (-i,0) {$X'_{j}$};
}
end{tikzpicture}
end{document}
add a comment |
up vote
7
down vote
accepted
up vote
7
down vote
accepted
Use the pgfmath
macros (pgfmathsetmacro
for float calculations and pgfmathtruncatemacro
if you only want the integer part).
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=0.4]
pgfmathsetmacrohalf {0.5};
foreach i in { 2, 4, 6}
{
pgfmathtruncatemacroj{i*half};
node[draw=none] at (i,0) {$X_{j}$};
node[draw=none] at (-i,0) {$X'_{j}$};
}
end{tikzpicture}
end{document}
Use the pgfmath
macros (pgfmathsetmacro
for float calculations and pgfmathtruncatemacro
if you only want the integer part).
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=0.4]
pgfmathsetmacrohalf {0.5};
foreach i in { 2, 4, 6}
{
pgfmathtruncatemacroj{i*half};
node[draw=none] at (i,0) {$X_{j}$};
node[draw=none] at (-i,0) {$X'_{j}$};
}
end{tikzpicture}
end{document}
edited Nov 11 at 15:26
answered Nov 11 at 14:57
TeXnician
23.7k62984
23.7k62984
add a comment |
add a comment |
up vote
7
down vote
You can do the calculations within the foreach
loop with
foreach i [evaluate=i as moitie using int(i/2)] in { 2, 4, 6}
see page 904 of manual 3.0.1a.
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=0.4]
foreach i [evaluate=i as moitie using int(i/2)] in { 2, 4, 6}
{
node[draw=none] at (i,0) {$X_{moitie}$};
node[draw=none] at (-i,0) {$X'_{moitie}$};
}
end{tikzpicture}
end{document}
add a comment |
up vote
7
down vote
You can do the calculations within the foreach
loop with
foreach i [evaluate=i as moitie using int(i/2)] in { 2, 4, 6}
see page 904 of manual 3.0.1a.
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=0.4]
foreach i [evaluate=i as moitie using int(i/2)] in { 2, 4, 6}
{
node[draw=none] at (i,0) {$X_{moitie}$};
node[draw=none] at (-i,0) {$X'_{moitie}$};
}
end{tikzpicture}
end{document}
add a comment |
up vote
7
down vote
up vote
7
down vote
You can do the calculations within the foreach
loop with
foreach i [evaluate=i as moitie using int(i/2)] in { 2, 4, 6}
see page 904 of manual 3.0.1a.
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=0.4]
foreach i [evaluate=i as moitie using int(i/2)] in { 2, 4, 6}
{
node[draw=none] at (i,0) {$X_{moitie}$};
node[draw=none] at (-i,0) {$X'_{moitie}$};
}
end{tikzpicture}
end{document}
You can do the calculations within the foreach
loop with
foreach i [evaluate=i as moitie using int(i/2)] in { 2, 4, 6}
see page 904 of manual 3.0.1a.
documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[scale=0.4]
foreach i [evaluate=i as moitie using int(i/2)] in { 2, 4, 6}
{
node[draw=none] at (i,0) {$X_{moitie}$};
node[draw=none] at (-i,0) {$X'_{moitie}$};
}
end{tikzpicture}
end{document}
edited Nov 11 at 15:13
answered Nov 11 at 15:02
AndréC
6,75711140
6,75711140
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%2f459473%2fhow-to-define-a-variable-as-another-variable-divided-by-two%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
Isn't it easier doing
node[draw=none] at (2*i,0) {$X_{i}$};
withforeach i in {1,2,3}
?– egreg
Nov 11 at 14:52
@egreg That is true, but I need the division or multiplication by 0.5 for a different reason.
– padawan
Nov 11 at 14:53
@egreg I just realized that I could also use the method that you suggested :)
– padawan
Nov 11 at 22:20