Newenvironment - find the length of input
up vote
2
down vote
favorite
I am trying to define a new environment where the input text is placed inside a minipage, which has width equal to the length of the input text (something like a variable width box). What I would like to have additional is a horizontal line over the box which has length more than the input text (say 1.5*input-text-width), as shown below:
Though there are many methods to create a variable width box, I didn't see a way to draw a line over the box which which has its length connected to the input text. I believe that determining the length of the input text is the right way to proceed. In newcommand, the length can be easily determined, since the input text can be called as #1. My question is how to decide the input text length for a newenvironment. More exactly, where is the text-body defined inside the newenviroment?
A minimum working example is:
documentclass{article}
newenvironment{varlength}{
begin{center}
rule{0.9textwidth}{0.8pt}
begin{minipage}{0.6textwidth}}{
end{minipage}
end{center}}
begin{document}
begin{varlength}
This is a text inside fixed length minipage with over-line
I want the same to be repeated for variable width box
end{varlength}
end{document}
environments lengths
add a comment |
up vote
2
down vote
favorite
I am trying to define a new environment where the input text is placed inside a minipage, which has width equal to the length of the input text (something like a variable width box). What I would like to have additional is a horizontal line over the box which has length more than the input text (say 1.5*input-text-width), as shown below:
Though there are many methods to create a variable width box, I didn't see a way to draw a line over the box which which has its length connected to the input text. I believe that determining the length of the input text is the right way to proceed. In newcommand, the length can be easily determined, since the input text can be called as #1. My question is how to decide the input text length for a newenvironment. More exactly, where is the text-body defined inside the newenviroment?
A minimum working example is:
documentclass{article}
newenvironment{varlength}{
begin{center}
rule{0.9textwidth}{0.8pt}
begin{minipage}{0.6textwidth}}{
end{minipage}
end{center}}
begin{document}
begin{varlength}
This is a text inside fixed length minipage with over-line
I want the same to be repeated for variable width box
end{varlength}
end{document}
environments lengths
Look forvarwidth
in the answers to the question marked as duplicate.
– egreg
Dec 1 at 16:13
@egreg, thanks for the link. But in my environment, there is a line which spans over the text and has a length equal to 1.2 times the input-text-length. That's why I was asking for a way to find input length. I could not find a way to fix it in the link you shared. Should I edit my question?
– Ashok
Dec 1 at 18:58
Sorry, but I don't understand.
– egreg
Dec 1 at 20:40
@egred, I have edited my question, sorry for the delayed response.
– Ashok
Dec 4 at 14:26
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am trying to define a new environment where the input text is placed inside a minipage, which has width equal to the length of the input text (something like a variable width box). What I would like to have additional is a horizontal line over the box which has length more than the input text (say 1.5*input-text-width), as shown below:
Though there are many methods to create a variable width box, I didn't see a way to draw a line over the box which which has its length connected to the input text. I believe that determining the length of the input text is the right way to proceed. In newcommand, the length can be easily determined, since the input text can be called as #1. My question is how to decide the input text length for a newenvironment. More exactly, where is the text-body defined inside the newenviroment?
A minimum working example is:
documentclass{article}
newenvironment{varlength}{
begin{center}
rule{0.9textwidth}{0.8pt}
begin{minipage}{0.6textwidth}}{
end{minipage}
end{center}}
begin{document}
begin{varlength}
This is a text inside fixed length minipage with over-line
I want the same to be repeated for variable width box
end{varlength}
end{document}
environments lengths
I am trying to define a new environment where the input text is placed inside a minipage, which has width equal to the length of the input text (something like a variable width box). What I would like to have additional is a horizontal line over the box which has length more than the input text (say 1.5*input-text-width), as shown below:
Though there are many methods to create a variable width box, I didn't see a way to draw a line over the box which which has its length connected to the input text. I believe that determining the length of the input text is the right way to proceed. In newcommand, the length can be easily determined, since the input text can be called as #1. My question is how to decide the input text length for a newenvironment. More exactly, where is the text-body defined inside the newenviroment?
A minimum working example is:
documentclass{article}
newenvironment{varlength}{
begin{center}
rule{0.9textwidth}{0.8pt}
begin{minipage}{0.6textwidth}}{
end{minipage}
end{center}}
begin{document}
begin{varlength}
This is a text inside fixed length minipage with over-line
I want the same to be repeated for variable width box
end{varlength}
end{document}
environments lengths
environments lengths
edited Dec 4 at 14:25
asked Dec 1 at 16:07
Ashok
367211
367211
Look forvarwidth
in the answers to the question marked as duplicate.
– egreg
Dec 1 at 16:13
@egreg, thanks for the link. But in my environment, there is a line which spans over the text and has a length equal to 1.2 times the input-text-length. That's why I was asking for a way to find input length. I could not find a way to fix it in the link you shared. Should I edit my question?
– Ashok
Dec 1 at 18:58
Sorry, but I don't understand.
– egreg
Dec 1 at 20:40
@egred, I have edited my question, sorry for the delayed response.
– Ashok
Dec 4 at 14:26
add a comment |
Look forvarwidth
in the answers to the question marked as duplicate.
– egreg
Dec 1 at 16:13
@egreg, thanks for the link. But in my environment, there is a line which spans over the text and has a length equal to 1.2 times the input-text-length. That's why I was asking for a way to find input length. I could not find a way to fix it in the link you shared. Should I edit my question?
– Ashok
Dec 1 at 18:58
Sorry, but I don't understand.
– egreg
Dec 1 at 20:40
@egred, I have edited my question, sorry for the delayed response.
– Ashok
Dec 4 at 14:26
Look for
varwidth
in the answers to the question marked as duplicate.– egreg
Dec 1 at 16:13
Look for
varwidth
in the answers to the question marked as duplicate.– egreg
Dec 1 at 16:13
@egreg, thanks for the link. But in my environment, there is a line which spans over the text and has a length equal to 1.2 times the input-text-length. That's why I was asking for a way to find input length. I could not find a way to fix it in the link you shared. Should I edit my question?
– Ashok
Dec 1 at 18:58
@egreg, thanks for the link. But in my environment, there is a line which spans over the text and has a length equal to 1.2 times the input-text-length. That's why I was asking for a way to find input length. I could not find a way to fix it in the link you shared. Should I edit my question?
– Ashok
Dec 1 at 18:58
Sorry, but I don't understand.
– egreg
Dec 1 at 20:40
Sorry, but I don't understand.
– egreg
Dec 1 at 20:40
@egred, I have edited my question, sorry for the delayed response.
– Ashok
Dec 4 at 14:26
@egred, I have edited my question, sorry for the delayed response.
– Ashok
Dec 4 at 14:26
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
The “length of the input” doesn't make much sense, because TeX typesets paragraphs at a fixed size, using the current value of the parameter hsize
(normally equal to textwidth
in LaTeX).
You can have minipages that adapt to the size of the material inside them using varwidth
:
documentclass{article}
usepackage{varwidth}
newsavebox{varlengthbox}
newenvironment{varlength}
{begin{lrbox}{varlengthbox}begin{varwidth}{textwidth}}
{end{varwidth}end{lrbox}
begin{center}
rule{1.5wdvarlengthbox}{0.4pt}\
usebox{varlengthbox}
end{center}}
begin{document}
begin{varlength}
This is a text inside fixed length\
minipage with over-line
I want the same to be repeated for\
variable width box
end{varlength}
end{document}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
The “length of the input” doesn't make much sense, because TeX typesets paragraphs at a fixed size, using the current value of the parameter hsize
(normally equal to textwidth
in LaTeX).
You can have minipages that adapt to the size of the material inside them using varwidth
:
documentclass{article}
usepackage{varwidth}
newsavebox{varlengthbox}
newenvironment{varlength}
{begin{lrbox}{varlengthbox}begin{varwidth}{textwidth}}
{end{varwidth}end{lrbox}
begin{center}
rule{1.5wdvarlengthbox}{0.4pt}\
usebox{varlengthbox}
end{center}}
begin{document}
begin{varlength}
This is a text inside fixed length\
minipage with over-line
I want the same to be repeated for\
variable width box
end{varlength}
end{document}
add a comment |
up vote
2
down vote
accepted
The “length of the input” doesn't make much sense, because TeX typesets paragraphs at a fixed size, using the current value of the parameter hsize
(normally equal to textwidth
in LaTeX).
You can have minipages that adapt to the size of the material inside them using varwidth
:
documentclass{article}
usepackage{varwidth}
newsavebox{varlengthbox}
newenvironment{varlength}
{begin{lrbox}{varlengthbox}begin{varwidth}{textwidth}}
{end{varwidth}end{lrbox}
begin{center}
rule{1.5wdvarlengthbox}{0.4pt}\
usebox{varlengthbox}
end{center}}
begin{document}
begin{varlength}
This is a text inside fixed length\
minipage with over-line
I want the same to be repeated for\
variable width box
end{varlength}
end{document}
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
The “length of the input” doesn't make much sense, because TeX typesets paragraphs at a fixed size, using the current value of the parameter hsize
(normally equal to textwidth
in LaTeX).
You can have minipages that adapt to the size of the material inside them using varwidth
:
documentclass{article}
usepackage{varwidth}
newsavebox{varlengthbox}
newenvironment{varlength}
{begin{lrbox}{varlengthbox}begin{varwidth}{textwidth}}
{end{varwidth}end{lrbox}
begin{center}
rule{1.5wdvarlengthbox}{0.4pt}\
usebox{varlengthbox}
end{center}}
begin{document}
begin{varlength}
This is a text inside fixed length\
minipage with over-line
I want the same to be repeated for\
variable width box
end{varlength}
end{document}
The “length of the input” doesn't make much sense, because TeX typesets paragraphs at a fixed size, using the current value of the parameter hsize
(normally equal to textwidth
in LaTeX).
You can have minipages that adapt to the size of the material inside them using varwidth
:
documentclass{article}
usepackage{varwidth}
newsavebox{varlengthbox}
newenvironment{varlength}
{begin{lrbox}{varlengthbox}begin{varwidth}{textwidth}}
{end{varwidth}end{lrbox}
begin{center}
rule{1.5wdvarlengthbox}{0.4pt}\
usebox{varlengthbox}
end{center}}
begin{document}
begin{varlength}
This is a text inside fixed length\
minipage with over-line
I want the same to be repeated for\
variable width box
end{varlength}
end{document}
answered Dec 4 at 14:54
egreg
703k8618733148
703k8618733148
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%2f462709%2fnewenvironment-find-the-length-of-input%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
Look for
varwidth
in the answers to the question marked as duplicate.– egreg
Dec 1 at 16:13
@egreg, thanks for the link. But in my environment, there is a line which spans over the text and has a length equal to 1.2 times the input-text-length. That's why I was asking for a way to find input length. I could not find a way to fix it in the link you shared. Should I edit my question?
– Ashok
Dec 1 at 18:58
Sorry, but I don't understand.
– egreg
Dec 1 at 20:40
@egred, I have edited my question, sorry for the delayed response.
– Ashok
Dec 4 at 14:26